Isha
Isha

Reputation: 27

java.lang.NoClassDefFoundError: com/healthmarketscience/jackcess/util/ErrorHandler in ms access connectivity with java8

I am trying to connect Ms Access database with java 8 version. But as in this version jdbcodbcbridge driver has been removed, so following jar files need to be included :

**ucanaccess-x.x.x.jar
HSQLDB (hsqldb.jar, version 2.2.5 or newer)
,Jackcess (jackcess-2.x.x.jar)
,commons-lang (commons-lang-2.6.jar, or newer 2.x version)
,commons-logging (commons-logging-1.1.1.jar, or newer 1.x version)**

I have bought all these jar files in my eclipse through Build Path option.

But still when i am executing the following code it is coming up with error as:

Exception in thread "main" java.lang.NoClassDefFoundError: com/healthmarketscience/jackcess/util/ErrorHandler at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at demo.JDBCDemo.main(JDBCDemo.java:11) Caused by: java.lang.ClassNotFoundException: com.healthmarketscience.jackcess.util.ErrorHandler at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 3 more

And my code is:

    import java.sql.*;
import java.util.*;

import com.healthmarketscience.jackcess.util.ErrorHandler;
public class JDBCDemo {
    public static void main(String args[]) throws Exception
    {
        Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
    Connection con=DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\isha\\Desktop\\StudentData.accdb");
    Statement stmt=con.createStatement();
    String str="insert into NameData values(4,'ram')";
    stmt.executeUpdate(str);
    String s="select * from NameData";
    ResultSet res=stmt.executeQuery(s);
    while(res.next()){
    System.out.println(res.getString(1)+":"+res.getString(2));
    Enumeration e=DriverManager.getDrivers();
    while(e.hasMoreElements()){
        Driver d=(Driver)e.nextElement();
        System.out.println(d.getClass().getName());
    }
    }
    }
}

Upvotes: 1

Views: 4965

Answers (2)

jamadei
jamadei

Reputation: 1710

You have an old obsolete version of jackcess in your classpath. Please add to your classpath ucanaccess.jar the jars in the folder lib of the specific ucanaccess distribution you're using.

Upvotes: 2

Djehenghizz
Djehenghizz

Reputation: 63

String str="insert into NameData values(4,'ram')";

in which columns you insert this values?

Upvotes: 0

Related Questions