1 public void batchInsertAlbum(final List list) {
2 this.execute(new SqlMapClientCallback() {
3 public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
4 executor.startBatch();
5 for (int i = 0; i < list.size(); i++) {
6 executor.insert("album.insert", list.get(i));
7 }
8 executor.executeBatch();
9 return null;
10 }
11 });
12 }
1 public void batchInsertImg(final List<Image> imgList) {
2 this.execute(new SqlMapClientCallback() {
3 public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
4 executor.startBatch();
5 final int batchSize = 200; //每200条提交一次
6 int count = 0;
7 for (Image image : imgList) {
8 executor.insert("image.insert", image);
9 if (++count % batchSize == 0) {
10 executor.executeBatch();
11 }
12 }
13 executor.executeBatch(); //提交剩余的
14 return null;
15 }
16 });
17 }