Using a Microsoft Access database with a Security workgroup file from Java
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.
Thank YOU!!!!!
I too struggled for hours in search of the SystemDB parameter. I saw it elsewhere, but did not know that was what I needed until I came accross your blog. THANKS!!!!