NetBeans IDE - ClassNotFoundException: net.ucanaccess.jdbc.UcanaccessDriver

53014
June 06, 2017, at 08:49 AM

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)

Answer 1

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.

READ ALSO
Restfb, multiple cities with the same name, java

Restfb, multiple cities with the same name, java

I get JSON object after asking restfb API with fetchObject methodI need to somehow handle the fact, that when user types in:

327
Obtaining a powerset of a set in Java

Obtaining a powerset of a set in Java

The powerset of {1, 2, 3} is:

292
How to disable user moving Progress Bar Javafx

How to disable user moving Progress Bar Javafx

Oddly enough individuals are allowed to go to the edges of my progress bar in the bottom right of this picture and move the progress bar left and right:

507
Convert hours, mins, secs String to hours

Convert hours, mins, secs String to hours

I want to convert a time in the below format into hours

439