oracle addbatch()用法实例详解
preparedstatement.addbatch()的使用
statement和preparedstatement的区别就不多废话了,直接说preparedstatement最重要的addbatch()结构的使用.
1.建立链接
connection connection =getconnection();
2.不自动 commit
connection.setautocommit(false);
3.预编译sql语句,只编译一回哦,效率高啊
preparedstatement statement = connection.preparestatement("insert into tablex values(?, ?)");
//记录1
statement.setint(1, 1);
statement.setstring(2, "cujo");
statement.addbatch();
//记录2
statement.setint(1, 2);
statement.setstring(2, "fred");
statement.addbatch();
//记录3
statement.setint(1, 3);
statement.setstring(2, "mark");
statement.addbatch();
//批量执行上面3条语句.
int [] counts = statement.executebatch();
//commit it 到(db)里面
以上就是oracle addbatch()的用法,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!