In this tutorial you will learn to solve java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver error.
If you are using jdk 1.8 and trying to connect java with MS Access database then you will get error java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver. This is because java 8 or jdk 1.8 does not support jdbc odbc bridge. To connect with ms access you have to import some libraries.
How to Solve java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver Error?
1. Download jars from below link and import in the ide you are using.
Link: http://www.mediafire.com/download/ahzw21rrp20qiw8/ucanaccess.rar
Also Read: How to Add or Import Jar in Eclipse Project
2. Below is the program to connect java 8 with ms access database.
package com; import java.sql.Connection; import java.sql.DriverManager; public class JDBCMSAccess { public static void main(String args[]){ //connection url String url = "jdbc:ucanaccess://D:\\Users\\TCP\\Documents\\Database1.accdb"; try { //establishing connection Connection con = DriverManager.getConnection(url); if(con!=null){ System.out.println("Connection Successful!"); con.close(); } } catch (Exception e) { e.printStackTrace(); } } }
Comment below if you are facing any problem.