运行登录屏幕时出现此错误,真的不确定问题是什么,因为我按照教程进行操作,对他来说效果很好,这是我的依赖项和代码
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Connection con = null;
PreparedStatement pst = null ;
ResultSet rs = null;
try{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\Morgan\\Documents\\Database1.accdb");
String sq1 = "select * from user_account where username = '"+ tfusr.getText() +"' and password = '"+ tfpwsd.getText() +"' ";
pst = con.prepareStatement(sq1);
rs = pst.executeQuery();
if(rs.next())
{
JOptionPane.showMessageDialog(null,"Login successfull");
}
else {
JOptionPane.showMessageDialog(null , "Login Failed");
}
}
catch(Exception e){
System.out.println(e);
}
这可能是由于password是保留字造成的。
所以,尝试一下:
String sq1 = "select * from user_account where username = '" + tfusr.getText() + "' and [password] = '" + tfpwsd.getText() + "'";