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");
    }
}
Community
  • 1
  • 1
thayer
  • 80
  • 1
  • 7

1 Answers1

1

It looks like you have a old, conflicting jackcess version in your classpath (jackcess1.x.x) besides the correct one: com.healthmarketscience.jackcess.Database is an interface since jackcess2.0.0. You should remove that jackcess1 jar.

jamadei
  • 1,700
  • 9
  • 8
  • The jackcess is 2.0.4 which is the most recent version. It is the commons-logging that is 1.1.1. Just to be sure I will try replacing the jackcess version that came with ucanaccess with the jackcess that comes from their own site. But I am not hopeful. – thayer Aug 16 '14 at 13:17
  • Yes, you don't have to replace the correct jackcess jar (2.0.4) but remove the wrong one from your classpath. There couldn't be another cause of the exception you're getting, you have another jackcess 1.x.x jar in your classpath or something dirty in your environment. – jamadei Aug 16 '14 at 16:31
  • I found the old jackcess (1.2.14.3), it is being used by the GDAL framework for my QGIS installation. I am now trying to figure out how to remove it from the JRE library in Eclipse. I seem to only have the ability to entirely switch libraries, but I do not have another that will work with ucanaccess. Do you have any further advice? – thayer Aug 17 '14 at 17:23
  • I was able to remove the older jackcess from the class path by creating a new JRE System Library, but it still gives the same error. The only way I was able to resolve this was by manually removing the older file from its folder. – thayer Aug 17 '14 at 22:44
  • In your build path you need the jars you mentioned and a cleaned JRE(you can do the dowload from an official source). Maybe the QGIS installation parts shouldn't be shared with other kind of projects. – jamadei Aug 18 '14 at 06:26