简体   繁体   English

在Java 9模块中找不到Derby驱动程序

[英]Derby driver not found in Java 9 module

I'm trying to get a Java 9 module to connect to the inbuilt Derby database (embed mode). 我正在尝试使用Java 9模块连接到内置的Derby数据库(嵌入模式)。 My module has a dependency on java.sql , but I'm not sure where to put the Derby driver. 我的模块依赖于java.sql ,但我不确定在哪里放置Derby驱动程序。

Here's my module-info.java : 这是我的module-info.java

module mymodule {
    requires java.sql;
}

Here's the Main.java code in the module that fails to execute: 这是模块中无法执行的Main.java代码:

public static void main(String[] args) {

...
    Connection conn;
    try {
        conn = DriverManager.getConnection("jdbc:derby:mysampledb");
        Statement s = conn.createStatement();
        s.executeUpdate("create table testtable (" +
            "id VARCHAR(256), " +
            "value VARCHAR(256)) ");
        s.close();

    }
    catch (SQLException e) {
        System.out.println("Error connecting " + e);
    }
}

This compiles fine, but does not execute. 这编译很好,但不执行。

java -cp derbyjars --module-path out -m mymodule/foo.Main

Error connecting java.sql.SQLException: No suitable driver found for jdbc:derby:mysampledb

How do I add the DB drivers? 如何添加数据库驱动程序? Is that using the -cp option? 这是使用-cp选项吗? I have placed all the derby jars in the folder derbyjars and I'm passing that to the -cp option. 我已将所有derby jar放在文件夹derbyjars ,并将其传递给-cp选项。 Is there another way to make the module see the drivers? 有没有其他方法让模块看到驱动程序?

The -cp parameter takes in the individual jar names. -cp参数接受各个jar名称。 Not the name of the folder containing the jars. 不是包含jar的文件夹的名称。 (Thanks @BryanPendleton). (谢谢@BryanPendleton)。

I changed my command to the one below, and it worked: 我将命令改为下面的命令,它有效:

java -cp "derbyjars/*" --module-path out -m mymodule/foo.Main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM