4

I'm trying to use UCanAccess to connect a Java application to an Access database but when I run my Java app I get the error that

UCANACCESS_HOME system variable isn't defined...

I have added the six jar files to the project library in NetBeans. I've also added the path to the directory where the ucanaccess-3.0.3.jar file is stored to the PATH system variable in Windows 10. I also tried creating a new system variable UCANACCESS_HOME with no luck.

Any help that could point me in the right direction would be greatly appreciated.

Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
user3692531
  • 51
  • 1
  • 5
  • 1
    Don't you put in the classpath ucanload.jar(for now only 5 jars), and please let me a bit of time to answer to this interesting question in a more structured way. – jamadei Dec 25 '15 at 22:07

3 Answers3

3

You can either

(1) ensure that your CLASSPATH includes the ucanaccess-x.x.x.jar and the four (4) jar files in the "lib" directory of the UCanAccess distribution,

or

(2) ensure that your CLASSPATH includes just the ucanload.jar from the "loader" folder, and set a Java system property named UCANACCESS_HOME when you launch the Java virtual machine, e.g., by using the -Dproperty=value switch

-DUCANACCESS_HOME=<directory into which you unpacked the UCanAccess binary distribution>

That is, UCANACCESS_HOME must point to the directory that directly contains ucanaccess-x.x.x.jar after decompressing the UCanAccess distribution zip file. For example:

-DUCANACCESS_HOME=/home/gord/Downloads/JDBC/UCanAccess-3.0.1-bin

The two configurations are mutually exclusive. The first one is the generally adopted one.

The second one leverages the JDBC driver classloading mechanism in order to load dependencies with a different classloader. If an application already uses specific versions of HSQLDB, commons-lang, commons-logging, and/or Jackcess then ucanload.jar can be used to avoid conflicts between different versions of those jars eventually used by your application. In other words, using this approach you can be sure that your application continues to use the (other) versions of HSQLDB, commons-lang, commons-logging, and/or Jackcess that it used before, while UCanAccess uses the ones in its distribution.

Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
jamadei
  • 1,680
  • 8
  • 8
  • I tried the first approach, adding to the "Path" system variable the directory where ucanaccess.jar exists and the lib directory where the other four jars exist and I am still getting an error that the "UCANACCESS_HOME system variable isn't defined:..." Is Path the incorrect system variable to use in? I would like to try the second approach. What are the steps to set -DUCANACCESS_HOME? – user3692531 Dec 27 '15 at 03:10
1

Thanks for the help jamadei.

I determined that the issue was with the path to the .mdb file in my code. Rather than using a relative path, I used an absolute. This wasn't an issue with the Ucanaccess driver.

In addition, I needed to remove the ucanload jar from the project.

user3692531
  • 51
  • 1
  • 5
  • Notice that Ucanaccess isn't an odbc driver but a pure java jdbc driver and I wrote my answer to help future readers and the ucanaccess users. From this point of view your answer may be misleading, the reason of the exception reported was an incorrect ucanaccess installation(I can remember what I meant when I wrote the code that throws the exception). A wrong path is another issue, so sorry ;-) – jamadei Dec 27 '15 at 16:54
0

After so many of tries finally I think I have found a solution... try to create a new database and restart your database and text editor