最新消息: 新版网站上线了!!!

spring jdbcTemplate批量插入,批量插入更新

jdbcTemplate批量插入、更新

解决方法:

List<Map<String, String>> extList = new ArrayList<Map<String, String>>();

HashMap<String, String> ext = new HashMap<String, String>(){

  {

       put("key", key);  

       put("value", value);  

   }

};

extList.add(ext);

StringBuilder sb = new StringBuilder();

sb.append("insert ignore into tb_call_ext(ext_id,c_id,ext_key,ext_val) values(?,?,?,?) ");

int[] extresult = jdbcTemplate.batchUpdate(sb.toString(), new BatchPreparedStatementSetter() {

@Override

public void setValues(PreparedStatement ps, int i) throws SQLException {

ps.setString(1, StringUtil.getid());

ps.setString(2, cid);

ps.setString(3, extList.get(i).get("key") + "");

ps.setString(4, extList.get(i).get("value") + "");

}

@Override

public int getBatchSize() {

return extList.size();

}

});


转载请注明:谷谷点程序 » spring jdbcTemplate批量插入,批量插入更新