Luis G Lombardi
Luis G Lombardi

Reputation: 1

Error - Java Connection With MS Access



I'm trying to do a connection with ms Access, but the only message that I recieve is:

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Cannot open database '(unknown)'. It may not be a database that your application recognizes, or the file may be corrupt.

    Connection con = null;
    Statement st = null;
    try {
         String url = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\\Users\\l7464434\\Desktop\\Teste MSAcc\\teste.mdb";       
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         con = DriverManager.getConnection(url, "", "");
         st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    }catch(Exception e){
        e.printStackTrace();
    }

Upvotes: 0

Views: 1272

Answers (1)

Martin
Martin

Reputation: 3058

Try to check wether Java can read the file:

File db = new File("C:\\Users\\l7464434\\Desktop\\Teste MSAcc\\teste.mdb");
if(db.exists()) {
    //do the rest of your code...
}

Also, make sure to implement the else and other error messages (don't remember if exists throws IOException)... This way you can be sure you see the file from your Java process.

Regards

Upvotes: 0

Related Questions