UCanAccess Initializer Error (compile/run without IDE)

喜夏-厌秋 提交于 2019-11-27 09:52:37

If you are not using an IDE then you need to specify the CLASSPATH entries for the JAR files of UCanAccess and all of its dependencies (HSQLDB, Jackcess, etc.). One way to do that is to use the -cp option of the java command when you run your code.

For example, after I compile the following code in "UcaNoIde.java" ...

import java.sql.*;

public class UcaNoIde {

    public static void main(String[] args) {
        String dbFileSpec = "C:/Users/Public/UCanAccessTest.accdb";
        String connStr = "jdbc:ucanaccess://" + dbFileSpec;
        try (Connection conn = DriverManager.getConnection(connStr)) {
            System.out.println("Connection established.");
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }

}

... into a "UcaNoIde.class" file I can run it using the following command at my Windows command prompt:

java -cp .;C:/Users/Public/Downloads/UCanAccess/ucanaccess-3.0.3.jar;C:/Users/Public/Downloads/UCanAccess/lib/commons-lang-2.6.jar;C:/Users/Public/Downloads/UCanAccess/lib/commons-logging-1.1.1.jar;C:/Users/Public/Downloads/UCanAccess/lib/hsqldb.jar;C:/Users/Public/Downloads/UCanAccess/lib/jackcess-2.1.3.jar UcaNoIde

(For Linux, et. al. the -cp entries will be separated by colons (:) instead of semicolons (;) and the file paths will be a bit different.)

Another possibility is to define a CLASSPATH environment variable with the same entries as in the -cp option above so you don't have to use -cp every time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!