Oracle addBatch()用法實(shí)例詳解
PreparedStatement.addbatch()的使用
Statement和PreparedStatement的區(qū)別就不多廢話了,直接說PreparedStatement最重要的addbatch()結(jié)構(gòu)的使用.
1.建立鏈接
1
|
Connection connection =getConnection(); |
2.不自動(dòng) Commit
1
|
connection .setAutoCommit( false ); |
3.預(yù)編譯SQL語句,只編譯一回哦,效率高啊
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
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(); //批量執(zhí)行上面3條語句. int [] counts = statement.executeBatch(); // Commit it 到(DB)里面 |
以上就是Oracle addBatch()的用法,如有疑問請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
原文鏈接:http://lanyan-lan.iteye.com/blog/260532