我使用下面的代码来更新或编辑Access数据库中的数据,但每次单击该按钮时都会出现此错误:
net.ucanaccess.jdbc.UcanaccessSQLException:意外结束语句
public void actionPerformed(ActionEvent e)
{
String employeeName = endrollNameFields.getText();
String employeeAddress = endrollAddressFields.getText();
String employeeStatus = endrollEmploymentStatusFields.getText();
String employeeDateOfMembership = dateOfMembershipFields.getText();
String employeeAge = ageFields.getText();
String employeMStatus = statusFields.getText();
String employeeBloodType = bloodTypeFields.getText();
String employeeDateBirth = birthDateFields.getText();
String employeeGender = genderFields.getText();
String beginningCapital = beginningCapitalFields.getText();
String grossSalary = grossSalaryFields.getText();
String salaryDeductions = salaryDeductionFields.getText();
String netSalary = netSalaryFields.getText();
try
{
//------------CREATE CONNECTION TO DATA BASE--------------/
String DBPAD = "sourceFolder/employeeTable2.mdb";
String DB = "jdbc:ucanaccess://" + DBPAD;
con = DriverManager.getConnection(DB);
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "Select * employeeTable2";
rs = st.executeQuery(sql);
if (rs != null)
while ( rs.next())
{
rs.updateString("Employee Name", employeeName);
rs.updateString("Employee Address", employeeAddress);
rs.updateString("Employee Status", employeeStatus);
rs.updateString("Employee Date of Membership", employeeDateOfMembership);
rs.updateString("Employee Age", employeeAge);
rs.updateString("Employee Marital Status", employeMStatus);
rs.updateString("Employee Blood Type", employeeBloodType);
rs.updateString("Employee Date Birth", employeeDateBirth);
rs.updateString("Employee Gender", employeeGender);
rs.updateString("Beginning Capital", beginningCapital);
rs.updateString("Gross Salary", grossSalary);
rs.updateString("Salary Deductions", salaryDeductions);
rs.updateString("Net Salary", netSalary);
rs.updateRow();
}
st.close();
con.close();
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql1 = "select * from employeeTable2";
rs = st.executeQuery(sql1);
JOptionPane.showMessageDialog(null, "<html>" + "<font color=\"#008000\">" + "<html><span style='font-size:1.5em'>Update to Data Base is Successful");
endrollNameFields.setText(" ");
endrollAddressFields.setText(" ");
endrollEmploymentStatusFields.setText(" ");
dateOfMembershipFields.setText(" ");
ageFields.setText(" ");
statusFields.setText(" ");
bloodTypeFields.setText(" ");
birthDateFields.setText(" ");
genderFields.setText(" ");
beginningCapitalFields.setText(" ");;
grossSalaryFields.setText(" ");
salaryDeductionFields.setText(" ");
netSalaryFields.setText(" ");
editFrame.dispose();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
}
});
答案 0 :(得分:4)
您在代码
中写了错误的SQL查询con = DriverManager.getConnection(DB);
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "Select * employeeTable2";
将其更改为
String sql = "Select * FROM employeeTable2";