简体   繁体   English

LoginForm:比较数据库中的用户名和密码

[英]LoginForm: Compare username & password from database

I am a beginner in using Java and MS Access. 我是使用Java和MS Access的初学者。

Basically, I need to pass a username and a password (which is encrypted with MD5) and compare it with the data in my database table. 基本上,我需要传递用户名和密码(使用MD5加密)并将其与数据库表中的数据进行比较。 If it is found, it should return a Boolean value true. 如果找到,则应返回布尔值true。

I get the following error message: 我收到以下错误消息:

ERROR: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x3b0 Thread 0xfd4 DBC 0x5a91fcc 错误:java.sql.SQLException:[Microsoft] [ODBC Microsoft Access驱动程序]常规错误无法打开注册表项临时(易失性)Ace DSN进程0x3b0线程0xfd4 DBC 0x5a91fcc

This is my function for checking passwords: 这是我检查密码的功能:

private boolean logChck(String username, String password)
     {
      String query;
      boolean login = false;

        try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        String filename = "D:/Sand/program/JavaNetbeans/AllCodesHere/TestingCode/src/TestingCode/HotMan2.accdb";
        String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=";
        database+= filename.trim() + ";DriverID=22;READONLY=true}"; 

        connection = DriverManager.getConnection( database ,"","");

        query = "SELECT (StfFirName, StfPassword) FROM Staff WHERE (StfFirName = ? AND StfPassword = ?)";
        PreparedStatement ps = connection.prepareStatement(query);
        ps.setString(1, username);
        ps.setString(2, password);
        ps.executeQuery();
        ResultSet rs = ps.executeQuery();

        String checkUser = rs.getString(1);
        String checkPass = rs.getString(2);

        if((checkUser.equals(username)) && (checkPass.equals(password)))
        {
            login = true;
        }
        else
        {
            login = false;
        }

        connection.close();  
      } 

       catch (Exception err) {
       System.out.println("ERROR: " + err);
       }                                                                      

    return login;
}

Seems like a permissions issue - check out this suggestion from MS support: http://support.microsoft.com/kb/295297 看起来像权限问题 - 从MS支持查看此建议: http//support.microsoft.com/kb/295297

Pasting relevant sections from there, as proposed in @minitech's comment: 从@ minitech的评论中提出的那里粘贴相关部分:

Cause: 原因:

The account that is being used to access the page does not have access to the HKEY_LOCAL_MACHINE\\SOFTWARE\\ODBC registry key. 用于访问该页面的帐户无权访问HKEY_LOCAL_MACHINE \\ SOFTWARE \\ ODBC注册表项。

Resolution: 解析度:

  1. Start Registry Editor (Regedt32.exe). 启动注册表编辑器(Regedt32.exe)。
  2. Select the following key in the registry: HKEY_LOCAL_MACHINE\\SOFTWARE\\ODBC 在注册表中选择以下项:HKEY_LOCAL_MACHINE \\ SOFTWARE \\ ODBC
  3. On the Security menu, click Permissions. 在“安全性”菜单上,单击“权限”。
  4. Type the required permissions for the account that is accessing the Web page. 键入访问网页的帐户所需的权限。
  5. Quit Registry Editor. 退出注册表编辑器。

Multiple things here. 这里有很多东西。

It's not a password problem; 这不是密码问题; it's a general connection problem. 这是一般的连接问题。 There is something about the filename and database name string workup that doesn't look right. 有一些关于文件名和数据库名称字符串的工作,看起来不正确。 Are the slashes going in the right direction? 斜线是否朝着正确的方向发展? Create a helloWorld program with just the connection string and get that running first. 使用连接字符串创建一个helloWorld程序并首先运行它。

You don't need to call executeQuery() twice: 您不需要两次调用executeQuery():

ps.executeQuery();   // get rid of this one
ResultSet rs = ps.executeQuery(); // leave this one.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM