数据库由于某种原因没有更新

时间:2016-07-21 18:12:52

标签: java mysql sql

此sql查询未更新数据库,而是返回错误。有什么建议吗?

                    PreparedStatement ps10 = con.prepareStatement("UPDATE payroll_system.payslip SET hours_worked = (SELECT SUM(Hours) FROM payroll_system.monthly_timesheet WHERE employeeID=?) WHERE employeeID=?");
                    ps10.setString(1, employee_id);
                    ps10.setString(2, employee_id);
                    ps10.executeUpdate();

monthly_timesheet表:

enter image description here

payslip表:

enter image description here

1 个答案:

答案 0 :(得分:0)

Insert don't have where clause  
"INSERT INTO payroll_system.payslip(expense_claims) 
 WHERE employeeID=? 
 SELECT SUM(expense) FROM payroll_system.expense_master"

最终你在寻找更新?

或使用

     "INSERT INTO payroll_system.payslip(expense_claims) 
      SELECT SUM(expense) FROM payroll_system.expense_mast"

更新

 PreparedStatement ps9 = con.prepareStatement("UPDATE payroll_system.payslip 
     SET expense_claims = (SELECT SUM(Expense) 
     FROM payroll_system.expense_master 
     WHERE employeeID=?) WHERE employeeID=?");

     ps9.setString(1, employee_id);
     ps9.setString(2, employee_id);
     ps9.executeUpdate();