1

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 2

2

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) {}
}
Sign up to request clarification or add additional context in comments.

1 Comment

In this way you pass user and pwd for connecting to database: my db is not protected, the tables are
1

You can supply the username and password in the JDBC connection string.

1 Comment

Do you mean the string like "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=myDB.accdb" ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.