Menu

Java 8 Eclapse connect to Microsoft Access, "ClassNotFoundException: net.ucanaccess.jdbc.UcanaccessDriver"

Help
Enshuo Hsu
2015-07-25
2015-07-26
  • Enshuo Hsu

    Enshuo Hsu - 2015-07-25

    Hello,
    I just downloaded ucanaccess. I'm facing a problem with the connection to Access 2007.
    I use Java 8, Eclipse, and I have followed the instruction on this webpage:
    http://stackoverflow.com/questions/21955256/manipulating-an-access-database-from-java-without-odbc?lq=1
    What I've done is:
    1, Downloaded ucanaccess with 5 .jar files
    UCanAccess (ucanaccess-2.x.x.jar)
    HSQLDB (hsqldb.jar, version 2.2.5 or newer)
    Jackcess (jackcess-2.x.x.jar)
    commons-lang (commons-lang-2.4.jar, or newer)
    commons-logging (commons-logging-1.0.4.jar, or newer)
    2, Put the .jar files above into my project's folder and added into library(Eclipse->window->Java->User Libraries->Add External JARs).
    3, Import java.sql.*;

    My code is:

    public static void main(String[] args){
        try {
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C:/Users/David/workspace/0724/test/test.accdb");         
        System.out.println("OK");
        } catch (SQLException | ClassNotFoundException e) {
        System.out.println("fail");
            e.printStackTrace();
        }
    
    }
    

    But it returns an exception:

    java.lang.ClassNotFoundException: net.ucanaccess.jdbc.UcanaccessDriver
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at WebRequest.main(WebRequest.java:11)

    It seems that the class of the driver is not found. But it is supposed to be in the 5 .jars I downloaded...
    I've been working on this for a long time. Please help me with this. Any of your suggestions are appreciated.

     
    • Enshuo Hsu

      Enshuo Hsu - 2015-07-25

      I just found the problem!!
      I did not successfully put the .jars in my referenced library... How stupid I am!
      Now it works~~

       
  • Marco Amadei

    Marco Amadei - 2015-07-26

    Nothing stupid.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.