I\'m trying to find the faster way to do batch insert.
I tried to insert several batches with jdbcTemplate.update(String sql), wher
Simply use transaction. Add @Transactional on method.
Be sure to declare the correct TX manager if using several datasources @Transactional("dsTxManager"). I have a case where inserting 60000 records. It takes about 15s. No other tweak:
@Transactional("myDataSourceTxManager")
public void save(...) {
...
jdbcTemplate.batchUpdate(query, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
...
}
@Override
public int getBatchSize() {
if(data == null){
return 0;
}
return data.size();
}
});
}