`
hzwowo
  • 浏览: 21172 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

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

    博客分类:
  • web
阅读更多
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  
格式还能再乱些吗?

相关推荐

Global site tag (gtag.js) - Google Analytics