一、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();
本文介绍如何使用PreparedStatement.addBatch()方法批量执行SQL语句。通过预编译SQL语句并为每条语句设置参数值,最后调用executeBatch()方法来一次性执行所有已添加的SQL语句。
1178

被折叠的 条评论
为什么被折叠?



