批处理更新(Batch Update)流程

con.setAutoCommit(false);// 取消自动提交
stmt = con.createStatement();
// 增加批处理语句
stmt. addBatch ("INSERT INTO COFFEES " +
 "VALUES('Amaretto', 49, 9.99, 0, 0)");
stmt.addBatch("INSERT INTO COFFEES " +
"VALUES('Hazelnut', 49, 9.99, 0, 0)");
stmt.addBatch("INSERT INTO COFFEES " +
"VALUES('Amaretto_decaf', 49, 10.99, 0, 0)");
stmt.addBatch("INSERT INTO COFFEES " +
"VALUES('Hazelnut_decaf', 49, 10.99, 0, 0)");
stmt.executeBatch(); // 执行批处理
con.commit();// 向数据库提交批处理,用 con.rollback( ) 回滚批处理操作
con.setAutoCommit(true); // 恢复自动提交

你可能感兴趣的:(批处理更新(Batch Update)流程)