一、PreparedStatement.addbatch() 方法使于批量执行SQL语句。使用方法如下:
1.预编译SQL语句:
PreparedStatement statement = connection.prepareStatement("INSERT INTO TABLEX VALUES(?, ?)");
2.为SQL插入值:
statement.setInt(1, 1);
statement.setString(2, "Cujo");
statement.addBatch();
statement.setInt(1, 2);
statement.setString(2, "Fred");
statement.addBatch();
statement.setInt(1, 3);
statement.setString(2, "Mark");
statement.addBatch();
3.批量执行上面3条语句.
int [] counts = statement.executeBatch();