首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

PreparedStatement.addbatch()的施用

2012-12-21 
PreparedStatement.addbatch()的使用一、PreparedStatement.addbatch() 方法使于批量执行SQL语句。使用方法

PreparedStatement.addbatch()的使用

一、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();??

热点排行