針對BatchPreparedStatementSetter的代碼

批量處理用的很少,做一個記錄




/**
* 批量更新數據

* @param forums
*/
public void addForums(final List<Forum> forums) {
final String sql = "INSERT INTO t_forum(forum_name,forum_desc) VALUES(?,?)";
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
public int getBatchSize() {
return forums.size();
}


public void setValues(PreparedStatement ps, int index)
throws SQLException {
Forum forum = forums.get(index);
ps.setString(1, forum.getForumName());
ps.setString(2, forum.getForumDesc());
}
});
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章