I have an INSERT ALL query in my program like:
INSERT ALL
You need to perform batch insert.
int batchSize = 100;
try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH)) {
YourMapper mapper = sqlSession.getMapper(YourMapper.class);
int size = list.size();
for (int i = 0; i < size;) {
mapper.insertRecord(list.get(i));
i++;
if (i % batchSize == 0 || i == size) {
sqlSession.flushStatements();
sqlSession.clearCache();
}
}
sqlSession.commit();
}
You should find an appropriate value for the batchSize
(it depends on various factors).
The insert statement is pretty straight forward.
<insert id="insertRecord">
INSERT INTO MYTABLE (COLUMN1, COLUMN2, COLUMN3)
VALUES (#{addrElement.element1}, #{addrElement.element2}, #{addrElement.element3})
</insert>
We have an FAQ entry.