How to solve java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver in Java 8

java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver exception comes in Java 8 because it has removed the JDBC ODBC bridge driver class "sun.jdbc.odbc.jdbcodbcdriver" from JDK and JRE. This class is required to connect any database using Object database connectivity driver e.g. Microsoft Access, but unfortunately you cannot use it from JDK 8 onward. In order to solve this error, just use Jackcess library or a commercial driver like HXTT. Normally, in pre Java 8 world, java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver error comes when you try to connect to Microsoft Access database from Java using JDBC and JDBC ODBC bridge driver is not available in classpath. If you remember, In order to open SQL connection to database, first step is to load and register the driver. In order to load driver, we use Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  and this method throws java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver, if ClassLoader is not able to find the requested class (sun.jdbc.odbc.JdbcOdbcDriver) in CLASSPATH. In order to connect to MS Access, we need type 1 JDBC driver, also known as JDBC ODBC bridge driver and the class in question, JdbcOdbcDriver is driver implementation to connect to Open database connectivity driver installed in machine.

Just remember that sun.jdbc.odbc.JdbcOdbcDriver is a standard class from JDK API and it doesn't come with any external JAR like other vendor database's JDBC drivers e.g. JDBC driver to connect Oracle database comes on ojdbc6.jar and MySQL driver comes in mysql-connector-java-5.1.23-bin.jar. JdbcOdbcDriver class is present in rt.jar, which is always included in Classpath, as this JAR file is part of the JRE.

Many newbie in Java programming prefer to connect to MS Access database from Java then bigger database like Oracle, SQL Server or MySQL. Even I have done the same when I first started learning JDBC, main reason for that was MS ACCESS comes as part of Microsoft Office and  was available in my machine. I didn't have to go with pain involved on installing Oracle, SQL Server or MySQL database, sometime even you don't even have administrator access in your machine to do that. BTW, there are several disadvantage of using JDBC ODBC Bridge driver, first it require ODBC driver to be installed in your machine, second it makes your code platform dependent. Using pure Java type 4 JDBC driver is best way to connect commercial database from Java programs. Almost all major database vendor provides type 4 JDBC driver now days, so its just matter of finding right version and dropping that JAR in classpath.

 java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver in Java 8

java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver in Java 8

JDBC-ODBC bridge driver has been marked as "don't use" for the last decade or so. It was present in Java 7 release but removed from Java 8 release onward. It might also not be available on non-Windows JVMs, as it makes no sense to have an ODBC-JDBC bridge driver on platforms on which ODBC does not exist e.g. Linux or Mac OS.  Here is the stacktrace of the error you get :

   java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(

That's all about java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver exception in Java 8. JDBC-ODBC bridge driver is buggy, slow and unsupported in many platforms, it may not even be available even in 64-bit Windows versions. You will get this exception if you try to connect to Microsoft Access database form Java 8 JRE or JVM, because JDBC-ODBC bridge driver is now removed. Consider using type 4 JDBC, pure Java driver with real database or if you still want to connect to MS access, use Jackcess library or a commercial driver like HXTT.

Related JDBC Tutorials and troubleshooting guide :

  • General Guide to solve java.lang.ClassNotFoundException in Java [guide]
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Java MySQL? [solution]
  • How to fix java.lang.ClassNotFoundException: org.postgresql.Driver error in Java? [solution]
  • How to fix java.lang.ClassNotFoundException: Error in Java? [solution]
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory? [solution]
  • How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver in Java? [solution]
  • How to connect Oracle database from Java Program? (example)
  • How to solve java.lang.unsatisfiedlinkerror no ocijdbc11 in java.library.path? (solution)

No comments :

Post a Comment