-1

这是我第一次尝试这样做......我试图获取到我的数据库的链接,然后显示一个表格以查看链接是否已建立。出于某种原因,它只是不起作用。这是我的代码:

package dbtest;
import java.io.*;
import com.healthmarketscience.jackcess.*; 
import java.util.logging.Level;
import java.util.logging.Logger;
public class DbTest {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    try
    {
     Database db = DatabaseBuilder.open(new File("Users\\ou_snaaksie\\NetBeansProjects\\dbTest\\MOVIES.mdb"));
     Table tblMOVIES = db.getTable("tblMOVIES");
        System.out.println(tblMOVIES.toString());


    } 
    catch (IOException ex) 
    {Logger.getLogger(DbTest.class.getName()).log(Level.SEVERE, null, ex);}

    }

}

我得到的错误是:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at com.healthmarketscience.jackcess.impl.DatabaseImpl.<clinit>(DatabaseImpl.java:91)
at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:170)
at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:193)
at dbtest.DbTest.main(DbTest.java:25)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
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)
... 4 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
4

1 回答 1

0

错误消息告诉您您的项目丢失commons-logging。正如 Jackcess 的依赖页面所提到的,除了 Jackcess .jar 文件,您还需要

  • commons-lang v2.x(commons-lang-2.4.jar,或更新版本),以及
  • commons-logging(commons-logging-1.0.4.jar,或更新版本)

因此,NetBeans 项目中的 Libraries 文件夹应如下所示:

图书馆.png

于 2014-08-26T16:54:07.827 回答