protected void execute ( String sqlStatement , PrintWriter out , boolean acceptFailure ) throws Exception { try ( Connection conn = dataSource . getConnection ( ) ) { try ( Statement stmt = conn . createStatement ( ) ) { boolean success = execute ( stmt , sqlStatement , out , acceptFailure ) ; // Loop over all kinds of results. while ( success ) { /* 'success' is not modified below this line */ int rowCount = stmt . getUpdateCount ( ) ; if ( rowCount > 0 ) { // -------------------------------------------------- // Result of successful INSERT or UPDATE or the like // -------------------------------------------------- if ( options . debug ) { out . println ( "Rows affected: " + rowCount ) ; out . flush ( ) ; } if ( stmt . getMoreResults ( ) ) { continue ; } } else if ( rowCount == 0 ) { // -------------------------------------------------- // Either a DDL command or 0 updates // -------------------------------------------------- if ( options . debug ) { out . println ( "No rows affected or statement was DDL command" ) ; out . flush ( ) ; } boolean moreResults ; try { moreResults = stmt . getMoreResults ( ) ; } catch ( SQLException sqle ) { // State: 24000 - Invalid cursor state // [Teradata: Continue request submitted but no response to return] if ( sqle . getSQLState ( ) . startsWith ( "24" ) ) { break ; } else { throw sqle ; } } if ( moreResults ) { continue ; } } else { // rowCount < 0 // -------------------------------------------------- // Either we have a result set or no more results... // -------------------------------------------------- ResultSet rs = stmt . getResultSet ( ) ; if ( null != rs ) { // Ignore resultset rs . close ( ) ; if ( stmt . getMoreResults ( ) ) { continue ; } } } // No more results break ; } } } catch ( SQLException sqle ) { out . println ( "Failed to execute statement: \n" + sqlStatement ) ; out . println ( "\n\nDescription of failure: \n" + Database . squeeze ( sqle ) ) ; out . flush ( ) ; throw sqle ; } catch ( Exception e ) { out . println ( "Failed to execute statement: \n" + sqlStatement ) ; out . println ( "\n\nDescription of failure: \n" + e . getMessage ( ) ) ; out . flush ( ) ; throw e ; } }
Executes an SQL statement .