My code like this:
That is not a batch operation.
It's trying to execute multiple statements with a single PreparedStatement#execute() call and Oracle's JDBC driver does not support it (correction: the driver supports it).
The correct way is to perform a real batch operation.
The mapper statement contains a plain UPDATE statement.
<update id="biz-update">
update biz_tbl
set freeze_amount = nvl(freeze_amount,0) + #{payAmount}
where id = #{cardId}
</update>
The below code executes batch operation.
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
try {
for (YourItem item : list) {
sqlSession.update("biz-update", item);
}
List<BatchResult> results = sqlSession.flushStatements();
int totalNumberOfAffectedRows = Arrays.stream(results.get(0).getUpdateCounts()).sum();
sqlSession.commit();
} finally {
sqlSession.close();
}
sqlSession#flushStatements() returns a list of BatchResult. In this case, there is only one statement in the batch, so the list size is 1. If you execute multiple statements (e.g. update table A, then insert into table B), the list may contain multiple BatchResults.BatchResult#getUpdateCounts() returns an int array. The first element (=int) is the number of rows updated by the first UPDATE, the second element is the number of rows updated by the second UPDATE, and so forth.