Solved

Using Password with dsnless connection to Access database

Posted on 2003-12-02
7
888 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
runtime exception 2 67
jboss wildfly 10.1 10 633
maven module vs maven project 3 121
program arguments vs VM arguments 4 60
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

710 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