Solved

Using Password with dsnless connection to Access database

Posted on 2003-12-02
7
887 Views
Last Modified: 2010-03-31
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
Comment
Question by:mre2me
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 9863533
have u tried:

con = DriverManager.getConnection(theurl, user, password);
0
 

Author Comment

by:mre2me
ID: 9865056
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
 
LVL 92

Expert Comment

by:objects
ID: 9865072
how abouts:

jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)}; DBQ=c:\demo\demo.mdb;UID=xyz; PWD=secret
0
Independent Software Vendors: 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!

 
LVL 35

Expert Comment

by:girionis
ID: 9865341
 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
 

Author Comment

by:mre2me
ID: 9867604
>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
 

Author Comment

by:mre2me
ID: 9871775
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
 
LVL 92

Expert Comment

by:objects
ID: 9871780
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
arguments to jar 5 39
how to install java on RHEL image on EC2 4 57
hibernate example using maven 12 77
ejb stateless example 2 42
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question