Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
126 views
in Technique[技术] by (71.8m points)

java - Jackcess "NoClassDefFoundError" exception

I am using jackcess for the conncetivity to my access database. But I am following exception

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/CompareToBuilder
    at com.healthmarketscience.jackcess.impl.RowIdImpl.compareTo(RowIdImpl.java:113)
    at com.healthmarketscience.jackcess.impl.IndexData$Entry.compareTo(IndexData.java:1838)
    at com.healthmarketscience.jackcess.impl.IndexData$Entry.compareTo(IndexData.java:1646)
    at java.util.Collections.indexedBinarySearch(Collections.java:273)
    at java.util.Collections.binarySearch(Collections.java:259)
    at com.healthmarketscience.jackcess.impl.IndexData$DataPage.findEntry(IndexData.java:2368)
    at com.healthmarketscience.jackcess.impl.IndexData.findEntryPosition(IndexData.java:722)
    at com.healthmarketscience.jackcess.impl.IndexData.access$3300(IndexData.java:56)
    at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.updatePosition(IndexData.java:2133)
    at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.restorePosition(IndexData.java:2072)
    at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.restorePosition(IndexData.java:2055)
    at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.beforeEntry(IndexData.java:2017)
    at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findPotentialRow(IndexCursorImpl.java:368)
    at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findFirstRowByEntryImpl(IndexCursorImpl.java:262)
    at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findFirstRowByEntry(IndexCursorImpl.java:135)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl$DefaultTableFinder.findRow(DatabaseImpl.java:1890)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl$TableFinder.findObjectId(DatabaseImpl.java:1799)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.readSystemCatalog(DatabaseImpl.java:804)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.<init>(DatabaseImpl.java:513)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.open(DatabaseImpl.java:386)
    at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:170)
    at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:193)
    at ass.Access.main(Access.java:25)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.builder.CompareToBuilder
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 23 more

I have used jdbc but it is not working either. How can solve my problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here's how I got Jackcess working, starting with a fresh install of NetBeans 7.4 on Windows 8:

I downloaded the latest Jackcess JAR file via the "Looking for the latest version?" link on files page. I saved it in the folder

C:UsersPublicJava

As listed on the Project Dependencies page for Jackcess, I downloaded the ZIPped binaries for the two required dependencies: commons-lang v2.x, and commons-logging v1.x. I unpacked the ZIP files into the above folder, so it now contained two sub-folders

C:UsersPublicJavacommons-lang-2.6
C:UsersPublicJavacommons-logging-1.1.3

I launched NetBeans and created a new Project (for a Java Application) named "myJackcessTest". I expanded the Project in the tree view, right-clicked "Libraries", chose "Add JAR/Folder...", and added the three JAR files:

Libraries.png

Once that was done, I created my little test app...

package myjackcesstest;

import com.healthmarketscience.jackcess.*;
import java.io.File;
import java.io.IOException;

public class MyJackcessTest {

    public static void main(String[] args) {
        try {
            Table table = DatabaseBuilder.open(new File("C:\Users\Public\Database1.accdb")).getTable("Clients");
            System.out.println(String.format("table contains %d row(s)", table.getRowCount()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

...and when I hit F6 it ran fine:

run:
table contains 1 row(s)
BUILD SUCCESSFUL (total time: 0 seconds)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...