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:-)
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?
ReplyDeleteI was able to create jdbc.jar and copied all the files as instructed,
ReplyDeleteI 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.
Thanks for your help, I was able to create my excel file successfully. Few clarification I want to make.
ReplyDelete1) 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.
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??
ReplyDeleteGood solution !
ReplyDeleteplease elaborate instructions...
ReplyDeleteif you want I can send you a 64 bit jar I build in Email.
DeletePlease send me the compiled jdbc.jar to diptacs@gmail.com
DeleteAlso, please write the step-wise instruction how to do the whole thing to copy-paste
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.
DeleteThanks in advance
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.
DeleteThanks in advance
hi all, i am stuck in the same situation, can you please help to send the jar file to me at dhuynh@nlstech.net
DeleteAppreciate.
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.
ReplyDeleteI'm on a Mac, using java 1.7.0_79-b15 64 bits
Thanks in advance
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
DeleteGlad that it works for you:-)
DeleteHi i am unable to create the jar file .. can you please send the jar file to my email vikkywaits@gmail.com
ReplyDeleteHello, It has stopped showing the exception as "ClassNotFoundException" .
ReplyDeleteI 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.
I am able to create jar file and placed in jdk and jre lib location.
ReplyDeleteI am able to create jar file and placed in jdk and jre lib location.but still i am getting ClassNotfoundException.
ReplyDeleteAlso followed "Kalim Khan" comments as well. Could you send me working inputs.
Thanks in advance.
This comment has been removed by the author.
ReplyDeleteGuys, Can any one send java7 jre 64bit and 32bit of "jdbc.jar" and "jdbcodbc.dll" to triveni.bika@gmail.com.
ReplyDeletePlease help me.
Will it be any difference if I consume java7 jre jars from windows7 to windows10 platform (or) vice versa ?
Hi All,
ReplyDeleteCan any one send compiled jdk7 jars and detailed steps to follow to "triveni.bika@gmail.com" .Please help me on this.
please send me also the jdk 7 jar file 64-bit to me to 4731sudhanshussb@gmail.com
ReplyDeleteCopy sun\jdbc and sun\security\action folders out,
ReplyDeleteplease tell me the meaning of this sentence.
ASAP.
That means, copy them to some other location (but maintain the same folder structure as it is).
DeleteCan you please tell me how do i restart the JVM, as mentioned in th last point?
ReplyDeleteReboot your machine or kill your java.exe/javaw.exe
Deletehi, I've tryed this but i've got the following error:
ReplyDeleteODBC Exception: JavaException: java.lang.NullPointerException: null
when i execute this : DriverManager.getConnection(dbUrl, dbUser, dbPassword);
have you an idea why ?
What is your parameters dbURL, dbUser and dbPassword?
DeleteHi everyone, I have the NullPointer error, when trying to get connection. Any idea?
ReplyDeleteThis works for me in 32-bit version, but not 64-bit.
ReplyDeleteI'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
ReplyDeleteHi 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.
ReplyDeleteThanks in advance
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!
ReplyDeleteI am having the same issue and would like the correct jar file Thanks!
ReplyDeleteI am having the same issue and would like the correct jar file Thanks!
ReplyDeleteworks just fine thank you
ReplyDeletei copied full rt file and renamed it jdbc.jar
I can't seem to find the jdbc.jar file.
ReplyDeleteDo 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.
Great!!!
ReplyDeleteIt works like a charm
Thanks man
Dear Albert
DeleteCan you please explain me how you made it step by step...?
Please...!
go through below link---
ReplyDeletehttps://community.yellowfinbi.com/knowledge-base/article/moving-the-jdbc-odbc-bridge-from-java-7-to-java-8
I get this error:
ReplyDeleteException 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!
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
ReplyDeleteHow can I achieve the same in Linux env. ?
ReplyDeleteIT's very informative blog and useful article thank you for sharing with us , keep posting learn more about Product engineering services | Product engineering solutions.
ReplyDeleteff
ReplyDelete