使用Jackcess库读取Access数据库

时间:2014-08-25 18:30:33

标签: java netbeans jackcess

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

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)

1 个答案:

答案 0 :(得分:0)

错误消息告诉您项目缺失commons-logging。正如Jackcess&#39; dependencies page,除了Jackcess .jar文件,您还需要

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

Libraries.png