What is the use of this spring class of the BatchPreparedStatementSetter class?

Can someone give me a brief description of its spring class

org.springframework.jdbc.core.BatchPreparedStatementSetter 

( JavaDoc API reference )

+4
source share
2 answers

It is used to bulk insert multiple rows at once.

This code will illustrate how it is used.

Take a look at the importEmployees method and everything should be clear.

+7
source

batchUpdate can be done using JdbcTemplate batchUpdate as follows.

 public int[] batchUpdate(final List<Actor> actors) { int[] updateCounts = jdbcTemplate.batchUpdate("update t_actor set first_name = ?, " + "last_name = ? where id = ?", new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setString(1, actors.get(i).getFirstName()); ps.setString(2, actors.get(i).getLastName()); ps.setLong(3, actors.get(i).getId().longValue()); } public int getBatchSize() { return actors.size(); } }); return updateCounts; } 
0
source

All Articles