首页 > 数据库技术 > 详细

Jdbc批量更新

时间:2017-09-25 17:13:15      阅读:194      评论:0      收藏:0      [点我收藏+]
 1 Connection conn = null;
 2         PreparedStatement stmt =  null;
 3         try{
 4             conn = JdbcUtil.getConnection();
 5             stmt = conn.prepareStatement("insert into t1 (id,name) values(?,?)");
 6             
 7             for(int i=0;i<10;i++){
 8                 stmt.setInt(1, i+1);
 9                 stmt.setString(2, "aa"+(i+1));
10                 stmt.addBatch();//向缓存中加的参数
11             }
12             
13             int [] ii = stmt.executeBatch();//批处理.每条语句影响的行数
14             
15             for(int i:ii)
16                 System.out.println(i);
17         }catch(Exception e){
18             e.printStackTrace();
19         }finally{
20             JdbcUtil.release(null, stmt, conn);
21         }

 

Jdbc批量更新

原文:http://www.cnblogs.com/duyunchao-2261/p/7592709.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!