Removal of JDBC ODBC bridge in java 8

2020-01-22 12:29发布

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?

6条回答
等我变得足够好
2楼-- · 2020-01-22 12:52

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 --

查看更多
▲ chillily
3楼-- · 2020-01-22 12:56

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

查看更多
男人必须洒脱
4楼-- · 2020-01-22 12:57

I know this question has been answered a long time back, but I wanted to highlight DataDirect's sequelink. In this blog https://www.progress.com/blogs/jdbc-odbc-bridge-replacement-yields-performance-boost the author talks about how their bridge can yield a 310% performance boost. The bridge's trial version can be downloaded here: https://www.progress.com/jdbc/sequelink

查看更多
闹够了就滚
5楼-- · 2020-01-22 13:02

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

查看更多
Root(大扎)
6楼-- · 2020-01-22 13:02

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 );
查看更多
三岁会撩人
7楼-- · 2020-01-22 13:05

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
查看更多
登录 后发表回答