问题
Can anyone give me short description about his spring class
org.springframework.jdbc.core.BatchPreparedStatementSetter
(JavaDoc API Link)
回答1:
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.
回答2:
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;
}
来源:https://stackoverflow.com/questions/4321784/what-is-the-use-of-this-spring-class-batchpreparedstatementsetter