Saturday, March 19, 2016

How to enable JDBC-ODBC bridge for JDK 8

So JDK8 has removed JDBC-ODBC bridge, for whatever the reason. But if you don't have the source code of your existing product and don't want to spend time to reverse engineering them,  they just don't work in JRE 8. 

Are you stuck with JRE 7 or older forever? Not necessarily. Follow the step below, you can enable JDBC-ODBC bridge in JDK 8.

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 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
8. Copy   jdbcodbc.dll from JRE\bin  of your JRE 7 installation to JRE\bin of your JRE 8 installation.
9. Restart your JVM.

Common errors and how to avoid them:

1. If you're using 64 bits Java 8, make sure that you create Java 7 jar file using Java 7 64 bits.  If you're using 32 bits Java 8, make sure that you create Java 7 jar file using Java 7 32 bits.

2. Make sure that your java.exe is the one you want to run. Often there are more than one java executables on your machine. They may be different version or different bits (32 vs. 64). Type java -version to confirm the java runtime. It would be the best if you have a new machine and install Java 8 SDK on the machine to test. Create your Java 7 jar file on a different machine and copy over. 

3. "Path not found" issue. This can be simply solved by setting the classpath. You need to set the class path something like this:
classpath=.;[file path to your jar file, for example, c:\JDK8\lib\jdbc.jar]; [All the other existing classpath]

You must have ".;" at the beginning of your classpath because otherwise, you may get "Could not find or load main class" error. 

Remember, after you set your classpath, double check it on the console to make sure that it is set correctly. On Windows, you need to close and reopen a new cmd window if you set it in the system environment setting.  

That's it. If you have questions, ask:-)





45 comments:

  1. I am having hard time compiling, do I need 32bit version or 64bit version of JRE 7 and I should use Java 8 (64 bit) to compile? DO you have have jdbc.jar for download?

    ReplyDelete
  2. I was able to create jdbc.jar and copied all the files as instructed,
    I also created CLASSPATH = C:\Program Files\Java\jdk1.8.0_60\jre\lib\jdbc.jar
    Now I am getting error: java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver.

    ReplyDelete
  3. Thanks for your help, I was able to create my excel file successfully. Few clarification I want to make.

    1) First make sure if your going for 64 bit environment choose Java JRE 7 or SDK 7 64 bit version.
    2) Once you have Separated the files in c:\sun folder run the command from c:\jar -cvf jdbc.jar sun.
    3) Once your jdbc.jar is created in my case I had to put it in C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext folder, instructions said to put it in lib which gave me the error class not found

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String connUrl = "jdbc:odbc:DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ="+Filename+".xls;DriverID=22;readonly=false"; // good 64 bit
    conn=DriverManager.getConnection(connUrl,"","");

    Thanks again you saved me tons of time and re coding.

    ReplyDelete
  4. Not Helpful I am mot able to create jar so can u please elaborate it more about the folder structure and how to fire command in cmd for creating final jar file??

    ReplyDelete
  5. please elaborate instructions...

    ReplyDelete
    Replies
    1. if you want I can send you a 64 bit jar I build in Email.

      Delete
    2. Please send me the compiled jdbc.jar to diptacs@gmail.com

      Also, please write the step-wise instruction how to do the whole thing to copy-paste

      Delete
    3. Hi I have created the jar file but I am still having the issue. Could you send me the jar file to my mail, v.vijay64@gmail.com . It would be great help to me.

      Thanks in advance

      Delete
    4. Hi I have created the jar file but I am still having the issue. Could you send me the jar file to my mail, v.vijay64@gmail.com . It would be great help to me.

      Thanks in advance

      Delete
    5. hi all, i am stuck in the same situation, can you please help to send the jar file to me at dhuynh@nlstech.net
      Appreciate.

      Delete
  6. Hi, I'd be happy if you could send me the jar file at j.lebomin@gmail.com. I found the directories you mention, but they contained no jdbc.
    I'm on a Mac, using java 1.7.0_79-b15 64 bits

    Thanks in advance

    ReplyDelete
    Replies
    1. Finally I got it from a windows installation package. For some reason, the mac one didn't contain the jdbc jar. I was on a 64 bits Windows 7 system, but even there I had to use the 32 bits version because I was getting null pointer exception when the JDBC was initializing... Thanks for the instructions, it was very helpful

      Delete
    2. Glad that it works for you:-)

      Delete
  7. Hi i am unable to create the jar file .. can you please send the jar file to my email vikkywaits@gmail.com

    ReplyDelete
  8. Hello, It has stopped showing the exception as "ClassNotFoundException" .
    I also added the classpath to the " lib" folder where i have located my jdbc.jar file.
    But after i run the program i am getting the error "Could not find or load main class"
    Please help me.

    ReplyDelete
  9. I am able to create jar file and placed in jdk and jre lib location.

    ReplyDelete
  10. I am able to create jar file and placed in jdk and jre lib location.but still i am getting ClassNotfoundException.

    Also followed "Kalim Khan" comments as well. Could you send me working inputs.

    Thanks in advance.

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Guys, Can any one send java7 jre 64bit and 32bit of "jdbc.jar" and "jdbcodbc.dll" to triveni.bika@gmail.com.

    Please help me.

    Will it be any difference if I consume java7 jre jars from windows7 to windows10 platform (or) vice versa ?

    ReplyDelete
  13. Hi All,
    Can any one send compiled jdk7 jars and detailed steps to follow to "triveni.bika@gmail.com" .Please help me on this.

    ReplyDelete
  14. please send me also the jdk 7 jar file 64-bit to me to 4731sudhanshussb@gmail.com

    ReplyDelete
  15. Copy sun\jdbc and sun\security\action folders out,
    please tell me the meaning of this sentence.
    ASAP.

    ReplyDelete
    Replies
    1. That means, copy them to some other location (but maintain the same folder structure as it is).

      Delete
  16. Can you please tell me how do i restart the JVM, as mentioned in th last point?

    ReplyDelete
    Replies
    1. Reboot your machine or kill your java.exe/javaw.exe

      Delete
  17. hi, I've tryed this but i've got the following error:
    ODBC Exception: JavaException: java.lang.NullPointerException: null
    when i execute this : DriverManager.getConnection(dbUrl, dbUser, dbPassword);
    have you an idea why ?

    ReplyDelete
    Replies
    1. What is your parameters dbURL, dbUser and dbPassword?

      Delete
  18. Hi everyone, I have the NullPointer error, when trying to get connection. Any idea?

    ReplyDelete
  19. This works for me in 32-bit version, but not 64-bit.

    ReplyDelete
  20. I'm trying to do this but it doesn't work with 32-bit version can someone help me or send me de jdbc.jar that they made in 32-bit version

    ReplyDelete
  21. Hi I have created the jar file but I am still having the issue. Could you send me the jar file to my mail, robertim.nagy@gmail.com . It would be great help to me.

    Thanks in advance

    ReplyDelete
  22. Hi, I created the jar file and copied both files as per the instructions. but still getting the same error driver not found. Could anyone please send me the 32 bit version jar file. Thanks in advance!

    ReplyDelete
  23. I am having the same issue and would like the correct jar file Thanks!

    ReplyDelete
  24. I am having the same issue and would like the correct jar file Thanks!

    ReplyDelete
  25. works just fine thank you
    i copied full rt file and renamed it jdbc.jar

    ReplyDelete
  26. I can't seem to find the jdbc.jar file.
    Do you mean to copy out the jdbc folder as a sub folder of the security/action folder?
    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
    Then the command line :
    jar -cvf jdbc.jar sun
    is that supposed to have 'java' or 'javaw' before the 'jar'?
    if not, I get :
    'jar' is not recognized as an internal or external command,
    operable program or batch file.

    ReplyDelete
  27. Great!!!

    It works like a charm

    Thanks man

    ReplyDelete
    Replies
    1. Dear Albert
      Can you please explain me how you made it step by step...?
      Please...!

      Delete
  28. go through below link---
    https://community.yellowfinbi.com/knowledge-base/article/moving-the-jdbc-odbc-bridge-from-java-7-to-java-8

    ReplyDelete
  29. I get this error:
    Exception in thread "main" java.lang.NoClassDefFoundError: sun/security/action/LoadLibraryAction
    at sun.jdbc.odbc.JdbcOdbc.(JdbcOdbc.java:72)
    at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:446)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:678)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:229)

    Any suggestions?

    Please and thank you!

    ReplyDelete
  30. A very excellent blog post. I am thankful for your blog post. I have found a lot of approaches after visiting your post. PS5Home.com

    ReplyDelete
  31. How can I achieve the same in Linux env. ?

    ReplyDelete
  32. IT's very informative blog and useful article thank you for sharing with us , keep posting learn more about Product engineering services | Product engineering solutions.

    ReplyDelete