0

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.

j3ca
  • 5
  • 1
  • 1
  • 7
  • 1
    The JDBC-ODBC bridge driver has been removed from Java 8. Have a look at http://stackoverflow.com/questions/19709843/jdbc-odbc-driver-connection – Dawood ibn Kareem Apr 10 '14 at 11:25
  • @David Wallace I can see those options in Win8.1 Control Panel --> System and Security --> Administrative Tools – mKorbel Apr 10 '14 at 11:45
  • @mKorbel It's not in the JDK. This is nothing to do with the Windows Control Panel. Oracle have simply decided to break Java's backwards compatibility by excluding the JDBC driver for the JDBC-ODBC bridge from what they ship. – Dawood ibn Kareem Apr 10 '14 at 11:48
  • @David Wallace thanks, good point – mKorbel Apr 10 '14 at 11:52
  • @DavidWallace Thank you so much! That didn't occur to me. I've installed jdk1.7, and now it works fine :) Cheers man – j3ca Apr 10 '14 at 12:18

1 Answers1

1

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

Community
  • 1
  • 1
Gord Thompson
  • 98,607
  • 26
  • 164
  • 342