0



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();
    }
  • check this http://stackoverflow.com/questions/6880879/how-to-connect-ms-access-database-using-java-program/13263007#13263007 – Rohan Jun 26 '13 at 13:32

1 Answers1

0

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

Martin
  • 2,894
  • 22
  • 37