37

Starting with Java 8, the JDBC-ODBC Bridge will no longer be included with the JDK.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // classNotFoundException is thrown

Is there any other solution connecting JDBC-ODBC Bridge?

assylias
  • 321,522
  • 82
  • 660
  • 783
Karthik
  • 1,152
  • 1
  • 10
  • 7

5 Answers5

32

We can still use JDBC-ODBC Bridge in java 8 too, just follow this simple recipe:

  1. Download a JDK 7 or JRE 7.
  2. Goto JRE\lib folder and find the rt.jar
  3. Unzip it (if you have WinRAR or 7zip installed) or you can rename it to rt.zip and unzip it.
  4. Copy sun\jdbc and sun\security\action folders out, keep the folder structure. i.e., you should have the folder structure like below:

    Sun --> Security --> Action
        --> JDBC
    
  5. Open a CMD window. Go to the parent folder of Sun folder. Run the command: jar -cvf jdbc.jar sun

  6. The above command will create a file named jdbc.jar
  7. Copy JDBC.jar to your JDK8 or JRE8 lib folder. If that doesn't work try the lib\ext folder.
  8. Copy jdbcodbc.dll from JRE\bin of your JRE 7 installation to JRE\bin of your JRE 8 installation.
  9. Restart your JVM.

How to enable JDBC-ODBC bridge for JDK 8

Murray
  • 315
  • 5
  • 21
frhack
  • 4,862
  • 2
  • 28
  • 25
  • 2
    Upvoting this solution, as it worked ok for me. But NB, you must copy to \lib\ext folder, and be careful to not copy 32-bit version to 64-bit version and vice verca. – runholen May 09 '16 at 13:18
  • Hi frank, @runholen, can you guys please help me fix the same issue, here is my question http://stackoverflow.com/questions/38616703/connecting-to-excel-using-jdbc-8 – user2423959 Jul 27 '16 at 16:31
  • 3
    Hi user2423959. Try downloading the files from my google drive, https://drive.google.com/folderview?id=0B7NI8e6ep6rPQ0paQllwUU9vUW8&usp=sharing Make sure to have both on the classpath. (Included file is for 64-bit odbc btw) – runholen Aug 02 '16 at 08:30
  • 1
    For step 1, an alternate is to unpack just what is needed instead of downloading and running the install. The windows exe can be opened with 7zip and by using unpack200, you can pull out rt.jar. You can pull out the dll too. http://www.brucalipto.org/java/how-to-create-a-portable-jdk-1-dot-7-on-windows/ – Dale Jan 06 '17 at 23:20
  • 1
    For step 7, if the JRE8 `lib` folder doesn't work try the JRE8 `lib\ext` folder. Putting it in the `lib` folder didn't work for me, but 'lib\ext` did. I tried add this to the answer, but got rejected. Someone else with more juju should add it to the answer. – Dale Jun 28 '17 at 14:57
  • @Dale I approved your edit. (other people had the same issue). Thanks. – frhack Jun 28 '17 at 15:17
  • Any idea, if that would be possible for the Active-X bridge as well? – Renato Heeb Sep 25 '17 at 12:42
  • @runholen Thanks for the files. I included the jdbc_64.jar in my application libraries and it worked like a charm. But is there going to be any issue if I run the complied application on a 32-bit jre, since I include only the 64-bit driver? – Shehan Thamel Apr 20 '18 at 06:05
  • Does it also work for java 11 ? – Charlo Poitras Sep 20 '22 at 14:01
  • I don't know at this moment – frhack Sep 20 '22 at 14:02
15

Well, in my opinion this blog entry by an Oracle employee says it all:

I would recommend that you use a JDBC driver provided by the vendor of your database or a commercial JDBC Driver instead of the JDBC-ODBC Bridge.

What kind of application are you using the JDBC-ODBC Bridge for?

  • If it is production code, you should IMHO replace the bridge with a real driver and the legacy database with a real one ASAP
  • If it is test code that interacts with an Access DB, Excel spreadsheet or whatever you can access through ODBC, try replacing it with a pure Java database like H2
  • If you use it for ad-hoc access to legacy Access DBs for, say, development and/or analytical purposes, and really can't or don't want to update anything, you can stick to a JDK 7 for quite a long while until its End-of-Life date and probably far beyond that
Robert Petermeier
  • 4,122
  • 4
  • 29
  • 37
  • 1
    As a complement to this answer, I would like to point out that you can use [Apache POI](http://poi.apache.org/) to read Excel SpreadSheet and [Jackcess](http://jackcess.sourceforge.net/) for reading Access database. Both are a bit more work than ODBC though. – Laurent Bourgault-Roy Apr 18 '14 at 21:37
  • 6
    An Oracle employee recommends changing your enterprise DB for lack of continued driver support. Classic. – BAR Jan 26 '15 at 19:23
  • @BAR: which "enterprise" DB doesn't have a proper JDBC driver? –  May 19 '15 at 11:10
  • 1
    @a_horse_with_no_name that is exactly my point. Any true enterprise DB will have JDBC – BAR May 19 '15 at 11:18
  • 1
    Is not always the best solution to replace an ODBC driver with a JDBC legacy one, eg: when using Sybase IQ, the ODBC driver works 500% faster than the JDBC one for OLAP. Just my experience. – ChoCho Nov 16 '18 at 17:09
12

Is there any other solution connecting JDBC-ODBC Bridge?

Sun's and Oracle's official positions have long been that --

the [JVM-bundled] JDBC-ODBC Bridge should be considered a transitional solution [...] Oracle does not support the JDBC-ODBC Bridge.

However, my employer, OpenLink Software, has produced enterprise-grade commercial Type 1 Bridges between JDBC and ODBC since JVM 1.0, and these are fully compatible with the current JVM 1.8. You can learn more here --

TallTed
  • 9,069
  • 2
  • 22
  • 37
  • Vote up for good answer. Could you point me to the license agreement on this Bridge driver? – Y123 Apr 08 '15 at 19:42
  • @YazadKhambata - I'm not sure what you're looking for. Possibly [this](http://www.openlinksw.com/licenses/)? You can also learn more [here](http://uda.openlinksw.com/jdbc-odbc-st/). – TallTed Apr 08 '15 at 22:06
10

I found a reasonable solution that allows for use of existing code with a change only to open database connection logic.

UCanAccess is an open-source, JDBC driver.

http://ucanaccess.sourceforge.net/site.html

That has two dependencies, one of which has two more dependencies.

jackcess-2.0.0.jar or later

commons-lang-2.4.jar

commons-logging-1.0.4.jar

hsqldb.jar(2.2.5)

Those are all open-source. Do an internet search, download, unzip if necessary and put all four jars plus the one for UCanAccess in a directory in your project (e.g. JDBC-to-MSAccess). If using Ecplise, add to your build path by choosing from the menu "Project / Properties / Java Compiler / Libraries / Add External JARs" and select all five jar files.

The connection logic is really simple:


String strConnectionString = "";
Connection conAdministrator = null;

// Register driver
Class.forName( "net.ucanaccess.jdbc.UcanaccessDriver" );

// System.getProperty( "user.dir" ) => Current working directory from where application was started

strConnectionString = "jdbc:ucanaccess://" + System.getProperty( "user.dir" )  + "\\Your-database-name.<mdb or accdb>";

// Open a connection to the database
conAdministrator = DriverManager.getConnection( strConnectionString );
Outlier
  • 146
  • 1
  • 3
  • 2
    Good advice for helping users who want to connect to Access databases (more details [here](http://stackoverflow.com/q/21955256/2144390)). Not a general ODBC solution, however. – Gord Thompson Dec 01 '14 at 16:15
1

Robert Petermeier gave a good point H2 drives supports ODBC through PostgreSQL driver, and you can install the driver accordingly the link from Stackoverflow Setting up PostgreSQL ODBC on Windows

Community
  • 1
  • 1
Singagirl
  • 465
  • 1
  • 3
  • 11
  • And I would like to say thank you to Robert Petermeier for his brilliant answer, since I migrated to H2 just in matter of 1 hour. Unfortunately due low reputation I can't rise rate of his answer but still can say thank you. – Singagirl Mar 24 '14 at 03:34