1

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)

screenshot.png

Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
Evan
  • 83
  • 8
  • 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](https://stackoverflow.com/a/21955257/2144390) for an example. – Gord Thompson Jun 05 '17 at 20:36
  • It works now, thank you very much! – Evan Jun 05 '17 at 21:06

1 Answers1

0

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.

Gord Thompson
  • 98,607
  • 26
  • 164
  • 342