Reputation: 33
I am trying to pass this query from my Java application but it is saying I have an error in the UPDATE line, but i cant find what is wrong? can you spot see what I am doing wrong?
int rs = st.executeUpdate("INSERT INTO timesheet (employeeID, statusCode, periodEndingDate, departmentCode, minutesMon,"+
"minutesTue, minutesWed, minutesThu, minutesFri, minutesSat, minutesSun)"+
" VALUES ('"+empID+"','"+statusCode+"','"+periodEndingDate+"','"+departmentCode+"','"+minutesMon+"','"+
minutesTue+"','"+minutesWed+"','"+minutesThu+"','"+minutesFri+"','"+minutesSat+"','"+minutesSun+"')"+
" ON DUPLICATE KEY UPDATE timesheet SET statusCode='"+statusCode+"', periodEndingDate='"+periodEndingDate+"', departmentCode='"+departmentCode+"',"+
" minutesMon = '"+minutesMon+"', minutesTue='"+minutesTue+"', minutesWed='"+minutesWed+"', minutesThu='"+minutesThu+"', minutesFri='"+minutesFri+"',"+
" minutesSat='"+minutesSat+"', minutesSun='"+minutesSun+"' WHERE periodEndingDate='"+periodEndingDate+"' AND employeeID='"+empID+"';");
Upvotes: 0
Views: 80
Reputation: 43309
You can't use a WHERE
clause with ON DUPLICATE KEY UPDATE
. It is updating the duplicate.
If you have a UNIQUE
index on (periodEndingDate, employeeID)
, it is already updating the correct row without the where clause. Also, lose the tablename and the SET
in the Update clause.
MySQL Docs on ON DUPLICATE KEY UPDATE
Upvotes: 2