Connect to Password Protected Access Database without creating DSN Object

Hi,

I am having some difficulty connecting to a password protected Access 2003 Database.

I no don抰 want to create a static DSN object and have found some help in this area in the forums, but I cannot get it to work for me ;-(

My original code (before I password protected the database) worked and was:

public MakeConnection()

{

url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + getPath() + "database.mdb";

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

connection = DriverManager.getConnection( url );

}

catch( Exception e )

{

System.out.println(e);

errorObtainingPath();

}

}

From what I read on the forums all I needed to do was modify the url string to the following:

url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + getPath() + "database.mdb;PWD=password;";

I have tried all sorts of computations of the string but I continually receive the error message:

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Not a valid password.

Any help would be greatly received,

Thanks in advance,

Coffee_Junkie

[1206 byte] By [Coffee_Junkiea] at [2007-11-27 8:51:05]
# 1

Have also found another version of the same String which isn't working either, but it must be something silly I am getting wrong?!?

Also have taken out the path variable to ensure it is nothing silly like that!

url = "jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:/Database.mdb";//;Uid=admin;Pwd=password";

Thanks again,

Coffee_Junkie

Coffee_Junkiea at 2007-7-12 21:03:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Hi, when I used old Access I connected with a string like yours:

String myDatabaseFile = "C:\\mydatabase.mdb";

String username = "Joe";

String password = "JoePass";

String url = "jdbc:odbc:;Driver={Microsoft Access Driver (*.mdb)};Dbq="+myDatabaseFile+";Uid="+username+";Pwd="+password+";";

This worked for me... is your user/pass correct?

Xtremebcna at 2007-7-12 21:03:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

What a Muppet!

Was thinking alone the same lines as your post, if it thinks the username or password is wrong maybe it is?!?

Anyway ?what I have found out is 厀ait for it

Access passwords are limited to 20 characters, but there is no audio feedback to show you have reached the limit. So if you look at the keyboard when you type (like I do) you are blissfully unaware the last four characters of your password have not been accepted!

Therefore as the Exception caught by my application said; my password was wrong!

Maybe this will help others out in the future - although I have a sinking feeling that maybe I am the only one here who could be so dumb!

Doh!

Coffee_Junkiea at 2007-7-12 21:03:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...