这个spring类BatchPreparedStatementSetter有什么用?

时间:2010-12-01 06:25:57

标签: java spring spring-jdbc

任何人都可以给我一些关于他的春课的简短描述

org.springframework.jdbc.core.BatchPreparedStatementSetter

JavaDoc API Link

2 个答案:

答案 0 :(得分:7)

它用于一次批量插入多行。

This code将说明它是如何使用的。

仔细看看importEmployees方法,一切都应该变得清晰。

答案 1 :(得分:0)

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;
}
相关问题