0

I am a beginner in using Java and 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. If it is found, it should return a Boolean value 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

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;
}
Ry-
  • 218,210
  • 55
  • 464
  • 476
Ishildur Baggins
  • 147
  • 1
  • 2
  • 10
  • possible duplicate of ["General error Unable to open registry key Temporary (volatile) ..." from Access ODBC](http://stackoverflow.com/questions/26244425/general-error-unable-to-open-registry-key-temporary-volatile-from-access) – Gord Thompson Oct 13 '14 at 13:54

2 Answers2

2

Seems like a permissions issue - check out this suggestion from MS support: http://support.microsoft.com/kb/295297

Pasting relevant sections from there, as proposed in @minitech's comment:

Cause:

The account that is being used to access the page does not have access to the HKEY_LOCAL_MACHINE\SOFTWARE\ODBC registry key.

Resolution:

  1. Start Registry Editor (Regedt32.exe).
  2. Select the following key in the registry: 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.
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

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.

You don't need to call executeQuery() twice:

ps.executeQuery();   // get rid of this one
ResultSet rs = ps.executeQuery(); // leave this one.
Buzz Moschetti
  • 7,057
  • 3
  • 23
  • 33