public static int[] executeBatch(Connection connection,String rawSqlQuery,int parametersPerBatch,List<Object> parameters) throws SQLException {
  Preconditions.checkArgument(parameters.size() % parametersPerBatch == 0);
  PreparedStatement stmt=null;
  try {
    stmt=connection.prepareStatement(rawSqlQuery);
    int numBatches=parameters.size() / parametersPerBatch;
    for (int batch=0; batch < numBatches; batch++) {
      for (int param=0; param < parametersPerBatch; param++) {
        JdbcUtils.bindParameter(stmt,param + 1,parameters.get(batch * parametersPerBatch + param));
      }
      stmt.addBatch();
    }
    return stmt.executeBatch();
  }
  finally {
    JdbcUtils.closeStatement(stmt);
  }
}

public static int [ ] executeBatch ( Connection connection , String rawSqlQuery , int parametersPerBatch , List < Object > parameters ) throws SQLException { Preconditions . checkArgument ( parameters . size ( ) % parametersPerBatch == 0 ) ; PreparedStatement stmt = null ; try { stmt = connection . prepareStatement ( rawSqlQuery ) ; int numBatches = parameters . size ( ) / parametersPerBatch ; for ( int batch = 0 ; batch < numBatches ; batch ++ ) { for ( int param = 0 ; param < parametersPerBatch ; param ++ ) { JdbcUtils . bindParameter ( stmt , param + 1 , parameters . get ( batch * parametersPerBatch + param ) ) ; } stmt . addBatch ( ) ; } return stmt . executeBatch ( ) ; } finally { JdbcUtils . closeStatement ( stmt ) ; } }
execute a batch update statement .
