conn.setAutoCommit(false); Statement s = conn.createStatement (); for (int i = 0; i < sql.length; i++) { s.addBatch(sql[i]); } // Execute the batch results = s.executeBatch(); // Verify the results if(results!=null){
for (int i=0;i<results.length;i++){ if (results[i]!=1){ System.out.println("Something failed."+i); conn.rollback(); break; } if (i==(results.length-1)){ System.out.println(i+" rows inserted by PreparedStatement."); flag=true; conn.commit(); } } }else{ conn.rollback(); } conn.close();
int[] results;
String[] sql;
......
conn.setAutoCommit(false);
Statement s = conn.createStatement ();
for (int i = 0; i < sql.length; i++) {
s.addBatch(sql[i]);
} // Execute the batch
results = s.executeBatch(); // Verify the results
if(results!=null){
for (int i=0;i<results.length;i++){
if (results[i]!=1){
System.out.println("Something failed."+i);
conn.rollback();
break;
}
if (i==(results.length-1)){
System.out.println(i+" rows inserted by PreparedStatement.");
flag=true;
conn.commit();
}
}
}else{
conn.rollback();
}
conn.close();