我正在使用sqlite数据库,并尝试检查输入字段中输入的用户名和密码是否与数据库匹配。但是我说
时出错[SQLITE_NOTADB]打开的文件不是数据库文件(文件不是数据库)
我无法跟踪问题所在,因为我的编码非常清晰,如下所示,请帮忙!
与数据库的连接:
try {
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:G:\\java\\GUI\\db.sql");
JOptionPane.showMessageDialog(null, "Connection Successful !");
return connection;
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
return null;
}
代码:
try {
String query = " select * from employee where UserName=? and Password=? ";
PreparedStatement preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1, userNameField.getText());
preparedStatement.setString(2, passwordField.getText());
ResultSet resultSet = preparedStatement.executeQuery();
int count = 0;
while (resultSet.next()) {
count++;
}
if (count == 1) {
JOptionPane.showMessageDialog(null, "UserName and Password is Correct");
}
else if (count > 1) {
JOptionPane.showMessageDialog(null, "UserName or Password is duplicate");
}
else {
JOptionPane.showMessageDialog(null, "UserName and Password is not Correct. Try Again Please ...");
}
preparedStatement.close();
resultSet.close();
} catch (SQLException exception) {
JOptionPane.showMessageDialog(null, exception);
System.err.println(exception.getClass().getName() + ": " + exception.getMessage() );
}