一、batchUpdate
final String sqlAdd="insert into wkrj_bus_kaohe(kaohe_id,kaohe_year,kaohe_date,kaohe_khqk,kaohe_khdc,"+
"kaohe_dp_yx,kaohe_dp_cz,kaohe_dp_yb,kaohe_dp_bcz,"+
"kaohe_mzScore,kaohe_mc,kaohe_person,addtimer,"+
"basicInfoId,bedept_id,be_type,user_id,check_type_id)"+
"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
JdbcTemplate.batchUpdate(sqlAdd,new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement ps, int i) throws SQLException {
Map<String, Object> map = queryForList.get(i);
if(!StringUtils.isEmpty(map)){
String checkid=Guid.getGuid();
ps.setString(1, checkid);
ps.setString(2, modle.getKaohe_year());
ps.setString(3, modle.getKaohe_date()==null?null:format.format(modle.getKaohe_date()));ps.setString(4, modle.getKaohe_khqk());
ps.setString(5, modle.getKaohe_khdc());ps.setInt(6, modle.getKaohe_dp_yx());
ps.setInt(7, modle.getKaohe_dp_cz());ps.setInt(8, modle.getKaohe_dp_yb());
ps.setInt(9, modle.getKaohe_dp_bcz());ps.setDouble(10, modle.getKaohe_mzScore());
ps.setString(11, modle.getKaohe_mc());ps.setString(12, modle.getKaohe_person());
ps.setString(13, format1.format(new Date()));ps.setString(14, map.get("basicInfoId")+"");
ps.setString(15, map.get("dept_id")+"");ps.setString(16, "ganbu");
ps.setString(17, modle.getUser_id());ps.setString(18,"8");
}
}
//返回更新的结果集条数
public int getBatchSize() {
return queryForList.size();
}
});
其中sqlAdd为sql语句,参数用?代替,遍历的时候
ps.setInt(7, modle.getKaohe_dp_cz());
其中7代表第七个?的值。
queryForList为list集合。