当前位置: 移动技术网 > IT编程>数据库>Oracle > Oracle addBatch()用法实例详解

Oracle addBatch()用法实例详解

2017年12月08日  | 移动技术网IT编程  | 我要评论

slimtype,王威电机,儿媳妇婉艳

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()的用法,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网