Blog信息 |
blog名称: 日志总数:1304 评论数量:2242 留言数量:5 访问次数:7597169 建立时间:2006年5月29日 |

| |
[iBatis]iBatis对批量update的支持 软件技术
lhwork 发表于 2008/3/11 16:23:33 |
最近遇到需要批量update数据的问题,一开始用了一个for循环去update,数据量大的时候效率很低。原因是for循环每次update一条语句,都是一次连接过程。遇到大批数据更新的时候,效率就可想而知了。在google上找了一遍,发现iBatis里有对批量update的支持,挺好的东西。
代码如下: final List tempList = list; try { if (List tempList != null) { template.execute( new SqlMapClientCallback() { public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); for (int i = 0, n = tempList.size(); i < n; i++) { executor.update("test.batchupdate",(Map)tempList.get(i)); } executor.executeBatch(); return null; } } ); } } 用法就是这么简单,但是其工作的原理还没搞懂。
|
|
回复:iBatis对批量update的支持 软件技术
游客(游客)发表评论于2008/11/15 22:40:17 |
SQL就支持啊
update T_table t set t.字段 = 1 where t.id in (1,2,3,4,5,6) |
|
» 1 »
|