What is the use of this spring class BatchPreparedStatementSetter?
-
29-09-2019 - |
Pergunta
Can anyone give me short description about his spring class
org.springframework.jdbc.core.BatchPreparedStatementSetter
Solução
It's used for bulk insertion of many rows at once.
This code will illustrate how it's used.
Take a good look at importEmployees
method, and everything should become clear.
Outras dicas
batchUpdate can be done using JdbcTemplate batchUpdate method 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;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow