Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC with MS Access

 
prasad appecherla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on a Desktop Java application which has to connect to a password protected MS ACCESS database.(Tools->Security->Set Database password->"test". I did not create any users/groups and using the default "Admin" account)

I tried with following code which works fine if I didnt set any password.
==================
import java.sql.*;
import java.util.*;

class connect2Access {



private void initializeConnection()
{

Connection con ;
try
{

// Load Class Definition for Database Driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// set this to a MS Access DB you have on your machine
String curDir = System.getProperty("user.dir");
String filename = curDir +"/test.mdb";

String database = "jdbcdbcriver={Microsoft Access Driver (*.mdb)};DBQ=";
database += filename.trim() + ";DriverID=22;READONLY=true;}";

// Get connection from the DriverManager
con = DriverManager.getConnection( database,"Admin","test" );


} catch (Exception e) {

System.out.println("Database Connection Problem");

}

}



public static void main(String s[]) {

(new connect2Access()).initializeConnection();

}

}
=====================

Am I doing anything wrong?
Pls. advise.

Thanks,
Prasad.

[edited to disable smilies]
[ December 09, 2004: Message edited by: Jeanne Boyarsky ]
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad,
so whats your question? that you are not able to connect to database if you set the password for the MS access ? what error is it throwing when u put the password for the access database ?


-Raj
 
prasad appecherla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.. I could not connect to the database.. Sorry .. I forget to mention my real problem.

Thanks,
Prasad.
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You still missed out to mention the actual error thrown.
why dont u print the stackTrace and let us know whats it saying when u protect the mdb database with password
 
prasad appecherla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StackTrace:
==========
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Not a valid password.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at connect2Access.initializeConnection(connect2Access.java:28)
at connect2Access.main(connect2Access.java:44)
Database Connection Problem
 
prasad appecherla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it..

Seems like i should not have "DriverID=22;"

It works fine with
=====================
String database = "jdbcdbcriver={Microsoft Access Driver (*.mdb)};DBQ=c:\\test.mdb;READONLY=true";

// Get connection from the DriverManager
con = DriverManager.getConnection( database,"Admin","test" );
======================


Thanks a lot for the responses.

Prasad.

[edited to disable smilies]
[ December 09, 2004: Message edited by: Jeanne Boyarsky ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic