JDBC with MS Access Database in Java 8

  • Since JDK 8, Java does not support ODBC driver for JDBC connectivity.
  • MS Access does not provide driver for JDK 8, therefore third party driver which is “UCanAccess” can be used to connect with MS Access database.
  • Download UCanAccess Driver.
  • Following is the way to connect with MSAccess database.
  • Please create the following table in Access : Student (Sno number, Sname Text(50), Scity(50))
import java.sql.*;

public class Main {

	public static void main(String[] args) throws Exception
	{		
		Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
		Connection conn = 
			DriverManager.getConnection("jdbc:ucanaccess://C:/raviroza/ravi.mdb");			
		String Q = "Insert into Student values (101,'raviroza.com','world wide web')";
		if(conn.createStatement().executeUpdate(Q)>0)
		{
			System.out.println("Recored added");
		}
	}
}