`
ywChen
  • 浏览: 118117 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

jdbc批量更新

    博客分类:
  • J2SE
阅读更多

 

 


  1.         Class.forName("com.mysql.jdbc.Driver");  
  2.         conn = DriverManager.getConnection(  
  3.                 "jdbc:mysql://localhost:3306/db""root""root");  
  4.         conn.setAutoCommit(false);  
  5.         pstmt = (PreparedStatement) conn  
  6.                 .prepareStatement(sql);         
  7.         for (int i = 0; i < terms.length -1; i++) {            
  8.             //此处注意setInt(1, i), 字段名称和栏目数必须匹配  
  9.             pstmt.setInt(1, i);  
  10.             pstmt.setString(2, terms[i]);  
  11.             pstmt.addBatch();  
  12.         
  13.         }  
  14.           
  15.         //增加到批量工作任务中  
  16.         pstmt.executeBatch();  
  17.         System.out.println(new Date());  
  18.         //提交执行  
  19.         conn.commit();  
  20.         pstmt.close();  
  21.         conn.close();  

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics