近期做了excel批量上传功能,发现jdbcTemplate预编译批量提交效率很高(对比jdbc直接批量提交),方法如下
public void batchUpdateList(final List list) {
String sql = "insert into specialtel(sn,tel,province,remark,provincename) values (?,?,?,?,?)";
this.batchUpdate(sql, new BatchPreparedStatementSetter() {
public int getBatchSize() {
return list.size();
}
public void setValues(PreparedStatement ps, int i)
throws SQLException {
SpecialTellEntity specialTellEntity = (SpecialTellEntity) list.get(i);
ps.setString(1, specialTellEntity.getSn());
ps.setString(2, specialTellEntity.getTel());
ps.setString(3, specialTellEntity.getProvince());
ps.setString(4, specialTellEntity.getRemark());
ps.setString(5, specialTellEntity.getProvincename());
}
});
}