I'am connecting my application to a Microsoft Access DB. The problem is that every table of this database is protected by a password(because the data in the table are imported from MS share point). Every time I try to execute a query by using a Statement object it ask me user and password. Is there a way to pass automatically user and pwd and avoid to insert them every time?
2 Answers
try out this
final String fileName = "c:/myDataBase.mdb";
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+fileName;
con = DriverManager.getConnection(url,"username","password");
} catch (Exception e) {
// Handle exceptions
...
} finally {
try { if(con!=null) {con.close();} } catch (Exception e) {}
}
1 Comment
user2541888
In this way you pass user and pwd for connecting to database: my db is not protected, the tables are
You can supply the username and password in the JDBC connection string.
1 Comment
user2541888
Do you mean the string like "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=myDB.accdb" ?