Archive

Archive for the ‘java’ Category

Using a Microsoft Access database with a Security workgroup file from Java

March 22nd, 2007

This is short and simple, but it took me forever to find this solution online so I’m posting it.

Situation is this: you need to access a Microsoft Access database from Java, and the database has workgroup security on it.

Connection conn;

String pathToDb = “path/dbfile.mdb”;

String pathToWorkgroupFile = “path/Security.mdw”;

String userName = “user name”;

String userPassword = “user password”;

try{

Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”).newInstance();

String conStr = “jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=”+pathToDb+”;SystemDB=”+pathToWorkgroupFile+”";

conn = DriverManager.getConnection(conStr,user,pass);

}catch (SQLException se){

System.out.println(”Problem connecting to database: “+se);

}catch (Exception ex){}

Thing that took me so long to find was “SystemDB” parameter name in the connection string. So there it is as another reference.

java