Issue
Trying to use UCanAccess to open an Access database with Java but it doesn't seem to be working. Here is the code:
import java.sql.*;
public class DbAccess2
{
public static void main(String[] args)
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://c:/myDB.mdb");
Statement s = conn.createStatement();
System.out.println("OK");
}
catch(Exception ex)
{
ex.printStackTrace();
// System.out.print("Not OK");
}
}
}
Here is the error I get:
java.lang.ClassNotFoundException: net.ucanaccess.jdbc.UcanaccessDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at DbAccess2.main(DbAccess2.java:10)
BUILD SUCCESSFUL (total time: 0 seconds)
Here's what my file looks like (NetBeans)
Solution
You have the UCanAccess jar file and its dependencies in a folder named lib
under "Libraries". Normally those jar files reside in "Libraries" itself, along with the JDK. It looks you unpacked a bunch of stuff and then tried to just add the folder, but that doesn't work: you need to add the actual jar files (not the folder they live in). See the NetBeans screenshot in this answer for an example.
Answered By - Gord Thompson