我正在开发一个登录系统,用于将用户输入的值与访问数据中的值进行比较,并且我在访问数据库时遇到了一些问题。这是显示的错误消息 “[Microsoft] [ODBC Microsoft Access驱动程序]找不到文件'(未知)'。”我非常感谢你的帮助,谢谢你。
这是我的代码:
private void BtnLoginActionPerformed(java.awt.event.ActionEvent evt) {
Connection conn = null;
String sql="Select Username, Password FROM EmployeeDetails";
try {
boolean found = false;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=AccountDetails.mdb");
Statement stmt=conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
user = Username.getText();
String pwd = new String (Password.getPassword());
while(rs.next()) {
String uname=rs.getString("Username");
String password=rs.getString("Password");
if ((user.equals(uname)) && (pwd.equals(password)))
{
found = true;
this.dispose();
}
}
if(found == false)
{
JOptionPane.showMessageDialog(null,"Username or password incorrect. Please try again.");
Username.setText("");
Password.setText("");
}
}
catch (Exception e){
JOptionPane.showMessageDialog(this, e.getMessage());
}
}