【发布时间】:2011-05-18 07:58:26
【问题描述】:
【问题讨论】:
标签: java spring spring-jdbc
【问题讨论】:
标签: java spring spring-jdbc
【讨论】:
batchUpdate 可以使用 JdbcTemplate batchUpdate 方法来完成,如下..
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;
}
【讨论】: