ฉันกำลังพยายามอัปเดตเป็นชุดสำหรับบันทึก 3,000 รายการ ใช้เวลาประมาณ 15 วินาทีจึงจะเสร็จสมบูรณ์ แต่การแทรกจะเกิดขึ้นภายใน 1 วินาที
รวม rewriteBatchedStatements=true
ไว้ด้วย ฉันจำเป็นต้องทำอะไรอีกหรือไม่?
ด้านล่างนี้คือรหัสของฉัน (ไม่รวมการจัดการข้อยกเว้นและส่วนการนับ/รหัสความสำเร็จและความล้มเหลว ซึ่งเหมือนกันสำหรับทั้งการอัปเดตและการแทรก)
เทคโนโลยีที่ใช้: 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();
}
} );