title: LoginForm: Compare username & password from database
body: <p>I am a beginner in using Java and MS Access.</p>
  
  <p>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.</p>
  
  <p>I get the following error message:</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>This is my function for checking passwords:</p>
  
  <pre><code>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)) &amp;&amp; (checkPass.equals(password)))
          {
              login = true;
          }
          else
          {
              login = false;
          }
  
          connection.close();  
        } 
  
         catch (Exception err) {
         System.out.println("ERROR: " + err);
         }                                                                      
  
      return login;
  }
  </code></pre>