Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 891
  • Last Modified:

Using Password with dsnless connection to Access database

I have created an application for distribution and do not want to allow the users to change my database, so I put a password on it. Because the users can create new databases with the program, I would like to use a DSNless connection to allow the user to change the databases easily.
I have successfully worked with the database through a DSN connection with the password, and through a DSNless connection without a password, but am unable to get in with a DSNless connection and a password.
I have read as many postings and topics using the main key words as I can find in the Java site APIs, forums, tutorials, bug databases, etc., but this topic is not addressed.
I have tried as many permutations on the advice I did find, and nothing works so far.  I keep getting a "Not a valid password" error.
I have included code that I am using to test this problem.

import java.sql.*;
import java.util.*;
import sun.jdbc.odbc.*;
public class testPassword {  
  private String theurl;  
  private String user = "";
  private String password = "";  
  private Connection con;  
  private Statement stmt;  
  public testPassword() {    
    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      theurl = "jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};" +             "DBQ=c:\\demo\\demo.mdb;Password=\"demo\"";
      boolean found = false;
      con = DriverManager.getConnection(theurl);
      try {
        stmt = con.createStatement();
        String pword = "";
        String query = "SELECT password FROM SysInfo";   // system Info        
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
          pword = rs.getString("password");
        }
        rs.close();
        stmt.close();
        con.close();
        System.out.println("Inner Password: " + pword);
        System.exit(0);
      } catch (Exception e) {
          System.out.println("Inner failed " + e.toString());
          System.out.println("Outer Password: " + password);
      }
   } catch (Exception ex) {
        System.out.println("Outer failed " + ex.toString());
        System.out.println("URL: " + theurl);
    }
  }

   public static void main(String [] args) {
     testPassword app = new testPassword();  
   }
}
Any help would be greatly appreciated.
0
mre2me
Asked:
mre2me
  • 3
  • 3
1 Solution
 
objectsCommented:
have u tried:

con = DriverManager.getConnection(theurl, user, password);
0
 
mre2meAuthor Commented:
I tried putting the password in the getConnection as well as in the connection string.  Not to mention putting it in both!  Same error message.

Any other ideas?
0
 
objectsCommented:
how abouts:

jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)}; DBQ=c:\demo\demo.mdb;UID=xyz; PWD=secret
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
girionisCommented:
 Try the following:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=c:\\d1.mdb;PWD=password","user","password");

  from: http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20572913.html?query=dsn+java+database+venci75&searchType=topic
0
 
mre2meAuthor Commented:
>jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)}; >DBQ=c:\demo\demo.mdb;UID=xyz; PWD=secret
I have tried this, both with and without the userid, using "UID" and "user id", and without quote marks and with single and double quote marks around the userid and the password. However, Access doesn't like it if you create users, so my userid was null.

>Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
>Connection conn = DriverManager.getConnection
     ("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);
     DBQ=c:\\d1.mdb;PWD=password","user","password");
Thanks, but I tried this,too.  It didn't work, either.

I will try these two items again.
I have tested this on Windows98SE and Windows 2000 with the latest Service Packs and updates.  I am currently in the process of checking it out on my server just to make sure that I can connect using ASP in a DSNless connection (testing the driver).  I'll get back to you on this.
0
 
mre2meAuthor Commented:
Solved!  I repeated as many of the permutations as I could and one finally worked.  objects, you were right on in your answer.  I know I had tried it before, but there must have been something different this time.  
Thank you!
0
 
objectsCommented:
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now