我正在尝试对3000条记录进行批量更新。大约需要15秒才能完成,但插入只需1秒。
包括 rewriteBatchedStatements=true
也。我还需要做什么吗?
下面是我的代码(不包括异常处理和成功与失败计数/ids部分)。它们对于更新和插入都是相同的)。
使用的技术:spring、jdbctemplate、mysql、java、intellij idea
result = jdbcTemplate.batchUpdate(
//"insert into xxx(aaa,bbb,item_code) values(?,?,?)",
"update ignore xxx set aaa = ?, bbb= ? where item_code = ?",
new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement ps,int i) throws SQLException {
ps.setDouble(1, Double.parseDouble(new JSONObject(jsonArray.get(i).toString()).get("aaa").toString()));
ps.setDouble(2, Double.parseDouble(new JSONObject(jsonArray.get(i).toString()).get("bbb").toString()));
ps.setString(3, new JSONObject(jsonArray.get(i).toString()).get("code").toString());
}
public int getBatchSize() {
return jsonArray.length();
}
} );
1条答案
按热度按时间hgtggwj01#
还包括useserverprestmts=false。
这里也提出了类似的问题:jdbc批插入性能
jdbc性能改进提示:http://javarevisited.blogspot.in/2012/01/improve-performance-java-database.html