Solved

Using Password with dsnless connection to Access database

Posted on 2003-12-02
7
883 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
  • 3
  • 3
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
Comment Utility
have u tried:

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

Author Comment

by:mre2me
Comment Utility
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
Comment Utility
how abouts:

jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)}; DBQ=c:\demo\demo.mdb;UID=xyz; PWD=secret
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 35

Expert Comment

by:girionis
Comment Utility
 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
Comment Utility
>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
Comment Utility
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
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now