gpt4 book ai didi

java - UCanAccess 中的 "Unexpected end of statement"错误

转载 作者:行者123 更新时间:2023-12-01 18:15:14 25 4
gpt4 key购买 nike

我使用下面的代码来更新或编辑 Access 数据库中的数据,但每次单击该按钮时都会出现此错误:

net.ucanaccess.jdbc.UcanaccessSQLException:unexpected end of statement

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);
}
}

});

最佳答案

您在代码中编写了错误的 SQL 查询

con = DriverManager.getConnection(DB);                  
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "Select * employeeTable2";

更改为

String sql = "Select * FROM employeeTable2";

关于java - UCanAccess 中的 "Unexpected end of statement"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30096012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com