这是我得到的错误:
“您的SQL语法有错误;请查看手册 对应于您的MySQL服务器版本,以便使用正确的语法 'Name ='Sanchez'附近,Middle Name ='Stark',First 名字='Ned',生日='1993-11'第1行“
private void UpdateButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
String WorkID = WorkIDField3A.getText();
String LastName = LastNameField3.getText();
String MiddleName = MidNameField3.getText();
String FirstName = FirstNameField3.getText();
String Birthday = BDayField3.getText();
String Age = AgeField3.getText();
String Gender = (String) GendCombo3.getSelectedItem();
String CStatus = (String) CStatCombo3.getSelectedItem();
String Dept = (String) DeptCombo3.getSelectedItem();
String Pos = PosField3.getText();
String WorkHrs3A = WorkHoursField3A.getText();
String WorkHrs3B = WorkHoursField3B.getText();
String WorkDaysFrom = (String) WorkDaysFromCombo.getSelectedItem();
String WorkDaysTo = (String) WorkDaysToCombo.getSelectedItem();
String HireDate = HireDateField3.getText();
String SQL = "UPDATE employees SET Last Name =?, Middle Name =?, First Name =?, Birthday =?, Age=?, Gender =?, Civil Status =?, Department =?, Position =?, Work Hours From(AM) =?, Work Hours To(PM) =?, Work Days From =?, Work Days To =?, Hire Date =? WHERE WorkID=?";
stmt = conn.prepareStatement(SQL);
stmt.setString(1, LastName);
stmt.setString(2, MiddleName);
stmt.setString(3, FirstName);
stmt.setString(4, Birthday);
stmt.setString(5, Age);
stmt.setString(6, Gender);
stmt.setString(7, CStatus);
stmt.setString(8, Dept);
stmt.setString(9, Pos);
stmt.setString(10, WorkHrs3A);
stmt.setString(11, WorkHrs3B);
stmt.setString(12, WorkDaysFrom);
stmt.setString(13, WorkDaysTo);
stmt.setString(14, HireDate);
stmt.setString(15, WorkID);
//Execute the SQL statement and update the table
stmt.executeUpdate();
JOptionPaneUpdate.showMessageDialog(this, "Update Succesful!");
}catch(Exception e)
{
JOptionPaneUpdateFail.showMessageDialog(this, e.getMessage());
}
答案 0 :(得分:5)
您的列是“LAST_NAME
”或“Last Name
”???
这是你的错误。 请勿在列名中使用空格。
如果真的非常需要,您可以使用以下方式转义列名:'Last Name'
答案 1 :(得分:3)
转义这些包含空格的名称。喜欢这个
UPDATE employees
SET `Last Name` =?,
`Middle Name` =?,
`First Name` =?,
Birthday =?,
Age=?,
Gender =?,
`Civil Status` =?,
...
WHERE WorkID=?
请尽量避免这些名字。