读书人

spring+ibatis 批量提交数据提拔性能

发布时间: 2013-11-08 17:52:14 作者: rapoo

spring+ibatis 批量提交数据提升性能
public
void
insertCreditItemBatch(
final
List<
credititem></
credititem>
creditItemList)

throws
DataAccessException{

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

public
Object
doInSqlMapClient(
SqlMapExecutor executor)

throws
SQLException
{

executor.startBatch
(
)
;

int
batch =
0
;

for
(
CreditItem creditItem:
creditItemList)
{

//调用获取sequence的方法。如果没有的话就去掉这行代码。

creditItem.setCreditItemId
(
getNextId(
)
)
;

//参数1为:ibatis中需要执行的语句的id

executor.insert
(
&
quot;
CreditItem_insertCreditItem&
quot;
, creditItem)
;

batch++;

//每500条批量提交一次。

if
(
batch==
500
)
{

executor.executeBatch
(
)
;

batch =
0
;

}

}

executor.executeBatch
(
)
;

return
null
;

}

}
)
;

}

    1 楼    longrui    2010-09-07              格式还能再乱些吗? 

读书人网 >软件架构设计

热点推荐