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
;

        }

    }
)
;

}

                            

你可能感兴趣的:(spring,ibatis)