阅读背景:

java批量更新小记录

来源:互联网 

 public void addEmployees(Connection conn, List<Employee> empList, int batchSize)               throws SQLException {           long bt = System.currentTimeMillis();           PreparedStatement stmt = null;           try {               String sql = SqlParser.getInstance().getSql("Employee.insert");               stmt = conn.prepareStatement(sql);               int count = 0;               for (Employee emp : empList) {                   stmt.setInt(1, emp.getId());                   stmt.setString(2, emp.getName());                   stmt.setInt(3, emp.getDepartment().getId());                   stmt.setString(4, emp.getDescription());                   stmt.addBatch();                                      count++;                                   if (count % batchSize == 0) {                       stmt.executeBatch();                   }               }                              stmt.executeBatch();              } finally {               long et = System.currentTimeMillis();               System.out.println(String.format("用时%dms", et-bt));               DBUtil.close(stmt);               DBUtil.close(conn);           }       }    public void addEmployees(Connection conn, List&l


你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: