1

I am trying to use UCanAccess to read data from a MS Access database in Mac OSX.8. I believe that I have set everything up according to the UCanAccess directions and those provided by Gord Tompson in a StackOverflow answer. This is the error that I am getting:

Exception in thread "main" java.lang.IncompatibleClassChangeError: Found class com.healthmarketscience.jackcess.Database, but interface was expected

      at net.ucanaccess.jdbc.DBReference.(DBReference.java:149)
      at net.ucanaccess.jdbc.DBReferenceSingleton.loadReference(DBReferenceSingleton.java:57)
      at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:100)
      at java.sql.DriverManager.getConnection(DriverManager.java:582)
      at java.sql.DriverManager.getConnection(DriverManager.java:207)
      at openACCDB.OpenACCDB.main(OpenACCDB.java:13)

My build path includes the following:

    commons-lang-2.6.jar
    commons-logging-1.1.1.jar
    hsqldb.jar
    jackcess-2.0.4.jar
    ucanaccess-2.0.8.jar
Does anyone have any advice? My understanding is that UCanAccess and Jackcess are platform independent, but do I need something in addition akin to the MS Jet Engine to run in Mac OSX?

This is my code:

package openACCDB

import java.sql.*;
import java.io.File;

public class OpenACCDB {
    public static void main(String args[]) throws ClassNotFoundException, 
            SQLException {
        Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
        String database = "/Users/george/Eclipse_Files/Java/GEOA_250/MyAccess.accdb";
        if ((new File(database)).exists()) {
            Connection conn = DriverManager.getConnection("jdbc:ucanaccess://"+database);
            Statement stmt = conn.createStatement();
            ResultSet rslt = stmt.executeQuery("SELECT [name] FROM [table1]");
            while (rslt.next())
                System.out.println(rslt.getString(1));
        }
        else System.out.println("The file "+database+"\n\tdoes not exist");
    }
}
4

1 回答 1

1

除了正确的版本之外,您的类路径 (jackcess1.xx) 中似乎还有一个旧的、冲突的 jackcess 版本:com.healthmarketscience.jackcess.Database 是自 jackcess2.0.0 以来的一个接口。你应该删除那个 jackcess1 jar。

于 2014-08-16T07:21:59.640 回答