3

我正在使用 jackcess 连接我的访问数据库。但我正在关注异常

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

我使用过 jdbc,但它也不起作用。如何解决我的问题?

4

2 回答 2

5

下面是我让 Jackcess 工作的方法,从在 Windows 8 上全新安装 NetBeans 7.4 开始:

我通过“寻找最新版本?”下载了最新的 Jackcess JAR 文件。文件页面上的链接。我保存在文件夹中

C:\用户\公共\Java\

正如 Jackcess 的Project Dependencies页面上列出的那样,我下载了两个所需依赖项的 ZIPped 二进制文件:commons-lang v2.x 和commons-logging v1.x。我将 ZIP 文件解压到上面的文件夹中,所以它现在包含两个子文件夹

C:\Users\Public\Java\commons-lang-2.6\
C:\Users\Public\Java\commons-logging-1.1.3\

我启动了 NetBeans 并创建了一个名为“myJackcessTest”的新项目(用于 Java 应用程序)。我在树形视图中展开 Project,右键单击“Libraries”,选择“Add JAR/Folder...”,并添加了三个 JAR 文件:

图书馆.png

完成后,我创建了我的小测试应用程序......

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();
        }
    }
}

...当我击中F6它时运行良好:

run:
table contains 1 row(s)
BUILD SUCCESSFUL (total time: 0 seconds)
于 2013-10-20T14:59:44.153 回答
3

Jackcess依赖Jakarta Commons Lang。您需要确保 commons lang 和其他依赖项在您的类路径中。

于 2013-10-18T13:22:59.797 回答