Obviously I’ve removed error handling and the query and Record object is notional and whatnot.Įdit: Since your original question was comparing the insert into foobar values (?,?,?), (?,?,?)…(?,?,?) method to Spring batch, here’s a more direct response to that: I was glad but I wanted to make my code better.Īfter that, I tried to use jdbcTemplate.batchUpdate in way like: jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() void setValues(PreparedStatement ps, int i) throws SQLException I checked the time using StopWatch and found out insert time: min, avg, max per batch Sql was builded by StringBuilder and looks like: INSERT INTO TABLE(x, y, i) VALUES(1,2,3), (1,2,3). I tried to insert several batches with jdbcTemplate.update(String sql), where
I’m trying to find the faster way to do batch insert.