public int[] executeBatch() throws SQLException {
  checkClose();
  if (batchQueries == null || batchQueries.size() == 0) {
    return new int[0];
  }
  MultiFixedIntExecutionResult internalExecutionResult=new MultiFixedIntExecutionResult(this,batchQueries.size(),0,false);
  boolean multipleExecution=false;
  lock.lock();
  try {
    QueryException exception=null;
    executing=true;
    executeQueryProlog();
    try {
      if (this.options.rewriteBatchedStatements) {
        boolean batchQueryMultiRewritable=true;
        for (        String query : batchQueries) {
          if (!ClientPrepareResult.isRewritableBatch(query,connection.noBackslashEscapes)) {
            batchQueryMultiRewritable=false;
            break;
          }
        }
        if (batchQueryMultiRewritable) {
          multipleExecution=true;
          protocol.executeBatchMultiple(protocol.isMasterConnection(),internalExecutionResult,batchQueries,resultSetScrollType);
          internalExecutionResult.updateResultsMultiple(batchQueries.size(),false);
        }
 else {
          protocol.executeBatch(protocol.isMasterConnection(),internalExecutionResult,batchQueries,resultSetScrollType);
        }
      }
 else {
        protocol.executeBatch(protocol.isMasterConnection(),internalExecutionResult,batchQueries,resultSetScrollType);
      }
    }
 catch (    QueryException e) {
      exception=e;
    }
 finally {
      internalExecutionResult.fixStatsError(batchQueries.size());
      if (exception != null && multipleExecution) {
        internalExecutionResult.updateResultsMultiple(batchQueries.size(),true);
      }
      executionResult=internalExecutionResult;
      executing=false;
      executeQueryEpilog(exception);
    }
    return internalExecutionResult.getAffectedRows();
  }
 catch (  SQLException sqle) {
    throw new BatchUpdateException(sqle.getMessage(),sqle.getSQLState(),sqle.getErrorCode(),internalExecutionResult.getAffectedRows(),sqle);
  }
 finally {
    lock.unlock();
    clearBatch();
  }
}

public int [ ] executeBatch ( ) throws SQLException { checkClose ( ) ; if ( batchQueries == null || batchQueries . size ( ) == 0 ) { return new int [ 0 ] ; } MultiFixedIntExecutionResult internalExecutionResult = new MultiFixedIntExecutionResult ( this , batchQueries . size ( ) , 0 , false ) ; boolean multipleExecution = false ; lock . lock ( ) ; try { QueryException exception = null ; executing = true ; executeQueryProlog ( ) ; try { if ( this . options . rewriteBatchedStatements ) { boolean batchQueryMultiRewritable = true ; for ( String query : batchQueries ) { if ( ! ClientPrepareResult . isRewritableBatch ( query , connection . noBackslashEscapes ) ) { batchQueryMultiRewritable = false ; break ; } } if ( batchQueryMultiRewritable ) { multipleExecution = true ; protocol . executeBatchMultiple ( protocol . isMasterConnection ( ) , internalExecutionResult , batchQueries , resultSetScrollType ) ; internalExecutionResult . updateResultsMultiple ( batchQueries . size ( ) , false ) ; } else { protocol . executeBatch ( protocol . isMasterConnection ( ) , internalExecutionResult , batchQueries , resultSetScrollType ) ; } } else { protocol . executeBatch ( protocol . isMasterConnection ( ) , internalExecutionResult , batchQueries , resultSetScrollType ) ; } } catch ( QueryException e ) { exception = e ; } finally { internalExecutionResult . fixStatsError ( batchQueries . size ( ) ) ; if ( exception != null && multipleExecution ) { internalExecutionResult . updateResultsMultiple ( batchQueries . size ( ) , true ) ; } executionResult = internalExecutionResult ; executing = false ; executeQueryEpilog ( exception ) ; } return internalExecutionResult . getAffectedRows ( ) ; } catch ( SQLException sqle ) { throw new BatchUpdateException ( sqle . getMessage ( ) , sqle . getSQLState ( ) , sqle . getErrorCode ( ) , internalExecutionResult . getAffectedRows ( ) , sqle ) ; } finally { lock . unlock ( ) ; clearBatch ( ) ; } }
execute statements . depending on option , queries mays be rewritten : those queries will be rewritten if possible to insert into . . . values ( . . . ) ; insert into . . . values ( . . . ) ; if option rewritebatchedstatements is set to true , rewritten to insert into . . . values ( . . . ) , ( . . . ) ;
