Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using Password with dsnless connection to Access database

Posted on 2003-12-02
7
Medium Priority
?
890 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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

730 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