I want to perform bulk insert into MariaDB using JdbcTemplate in Spring, but even when I append ?rewriteBatchedStatements=true to the jdbc-url, the inserts are still being done one by one.
my code works like this
INSERT INTO tbl (1, 2, ...) VALUES (val1, val2, ...) INSERT INTO tbl (1, 2, ...) VALUES (val1, val2, ...) INSERT INTO tbl (1, 2, ...) VALUES (val1, val2, ...)
i wanna this INSERT INTO tbl (1, 2, ...) VALUES (val1, val2, ...), (val1, val2, ...), ...
Is there any other way? What am I missing?
This is my code down here
spring.datasource.jdbc-url=jdbc:log4jdbc:mariadb://ip/db?rewriteBatchedStatements=true&profileSQL=true&logger=Slf4JLogger&maxQuerySizeToLog=999999
public void insertBatch(List<object> objectList) {
String sql = "";
sql += "INSERT INTO TBL_NAME" +
" (columns1, 2...) " +
"VALUES (?, ?...) ";
jdbcDBTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
object object = objectList.get(i);
ps.setInt(1, object.getCol1());
ps.setInt(2, object.getCol2());
}
@Override
public int getBatchSize() {
return tblInfoDetailList.size();
}
});
it's toooo slow.. plz help me