我想在 Java 8 下使用 UCanAccess 创建一个 Access 数据库连接。这是我的代码:
String employeeName = endrollNameFields.getText();
String employeeAddress = endrollAddressFields.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 * from employeeTable2";
rs = st.executeQuery(sql);
rs.moveToInsertRow();
rs.updateString("Name", employeeName);
rs.updateString("Address", employeeAddress);
rs.insertRow();
st.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'>Employee Successfuly Inserted to Data Base");
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
我在我的 JTextField 中输入了条目,但是当我单击包含上面代码的按钮时,会出现此错误消息:
net.ucanaccess.jdbc.Ucanaccess SQLException:invalid cursor state: 所有列必须在插入前设置
我的代码中缺少或缺少什么?