在Java 9模块中找不到Derby驱动程序 [英] Derby driver not found in Java 9 module

查看:74
本文介绍了在Java 9模块中找不到Derby驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取一个Java 9模块来连接到内置的Derby数据库(嵌入模式).我的模块依赖于java.sql,但是我不确定将Derby驱动程序放在哪里.

I'm trying to get a Java 9 module to connect to the inbuilt Derby database (embed mode). My module has a dependency on java.sql, but I'm not sure where to put the Derby driver.

这是我的module-info.java:

module mymodule {
    requires java.sql;
}

这是模块中执行失败的Main.java代码:

Here's the Main.java code in the module that fails to execute:

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

如何添加数据库驱动程序?那是使用-cp选项吗?我已将所有德比jars放在文件夹derbyjars中,并将其传递给-cp选项.有没有另一种方法可以使模块 see 驱动程序?

How do I add the DB drivers? Is that using the -cp option? I have placed all the derby jars in the folder derbyjars and I'm passing that to the -cp option. Is there another way to make the module see the drivers?

推荐答案

-cp参数采用各个jar名称.不是包含jar的文件夹的名称. (感谢@BryanPendleton).

The -cp parameter takes in the individual jar names. Not the name of the folder containing the jars. (Thanks @BryanPendleton).

我将命令更改为以下命令,并且有效:

I changed my command to the one below, and it worked:

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

这篇关于在Java 9模块中找不到Derby驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆