我试图从我的Java应用程序传递此查询,但它说我在UPDATE行中有错误,但我找不到有什么问题?你能看到我做错了吗?
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+"';");
答案 0 :(得分:2)
您不能在WHERE
中使用ON DUPLICATE KEY UPDATE
子句。它正在更新副本。
如果UNIQUE
上有(periodEndingDate, employeeID)
索引,则它已经在没有where子句的情况下更新了正确的行。此外,丢失表名和Update子句中的SET
。