Question

I am trying to connect Java app to MSAccess in NetBeans IDE (pls don't tell me not to use Access, because we are using it in classes, and that's just it for now :)). I didn't have this problem on Windows 7, and I couldn't find answer using Google, so I decided to post this question. So, it's like this, I have:

  • Windows 8.1 (64-bit)
  • Java jdk1.8.0 (32-bit)
  • NetBeans IDE 8.0, and NetBeans jdk home (from netbeans.conf) is: "C:\Program Files (x86)\Java\jdk1.8.0", so it's using 32-bit jdk.

Code for loading driver:

public void loadDriver() throws RuntimeException {
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    } catch (Exception e) {
        throw new RuntimeException("Could not load driver!");
    }
}

Code for opening connection:

public void openConnection() throws RuntimeException {
    try {
        connection = DriverManager.getConnection("jdbc:odbc:db");
        connection.setAutoCommit(false);
    } catch (Exception e) {
        throw new RuntimeException("Could not connect!");
    }
}

Of course, there's an attribute: private Connection connection; (and import java.sql.Connection;)

There is a problem at loading driver - it always says "could not load driver". If I have to post more code or change something in what I've posted, please tell me and I will.

I went to: SysWOW64 - odbcad32.exe - Add... - Microsoft Access Driver (*.mdb, *.accdb), and then for Data source name I've put of course "db" (like in my code above) and selected the database (.accdb file) that I will use. And I don't know if it is the Windows 8 issue or I'm forgetting something, but I really have no clue how to make it work.

Was it helpful?

Solution

The JDBC-ODBC Bridge has been removed from Java 8. For an alternative, see the related question here:

Manipulating an Access database from Java without ODBC

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top