posts - 41, comments - 15, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

ibatis批量插入表例子

Posted on 2012-02-15 14:00 yuhaibo736 阅读(2014) 评论(0)  编辑  收藏

public Integer batchInsertEntitylist(final List<Entity> list) {

  return (Integer) this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {

   public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {

    executor.startBatch();
    int batch = 0;
    int count = 0;
    for (Entity entity: list) {
     executor.insert("insertEntitylist", entity);
     batch++;
     if (batch == 500) {
      executor.executeBatch();
      batch = 0;
     }
    }
    executor.executeBatch();
    count = 1;
    return count;
   }

  });
 }


只有注册用户登录后才能发表评论。


网站导航: