gpt4 book ai didi

java - 从位于jdk1.7.0_06的eclipse中的JAVA DB中检索数据

转载 作者:搜寻专家 更新时间:2023-10-30 23:16:53 24 4
gpt4 key购买 nike

我正在尝试检索安装在位于 jdk1.7.0_06 中的数据库服务器 JAVA DB 上的数据。我能够连接到服务器并创建数据库。但是我在编译和运行时遇到以下错误:

No suitable driver found for jdbc:derby:AddressBook

请你帮帮我!谢谢

最佳答案

我说,“我想知道您是否需要像 Java DB 教程建议的那样设置 derby.system.home 属性。您尝试过这个吗?像 System.setProperty( "derby.system.home", DERBY_HOME_PATH); 其中第二个参数是数据库主目录的路径。"

然后你回答:

@HovercraftFullOfEels, i think i didn't but i am sure that i have set some envariable variables via command line.

@Dorji:虽然这并没有在您的 JVM 中设置系统属性。我仍然认为您需要在使用数据库之前设置此属性。例如,

public class Test {
public static final String DERBY_HOME = "derby.system.home";

// ***** the two Strings below will be different for you *****
public static final String DERBY_HOME_PATH = "D:/DerbyDB";
private static final String DB_NAME = "sample";

public static void main(String[] args) {
System.setProperty(DERBY_HOME, DERBY_HOME_PATH);
Connection conn = null;
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
conn = DriverManager.getConnection("jdbc:derby:" + DB_NAME);

} catch (InstantiationException | IllegalAccessException
| ClassNotFoundException | SQLException e) {
e.printStackTrace();
} finally {
if (conn == null) {
System.exit(-1);
}
}

// .... etc...

我的 derby.system.home 目录是 D/:DerbyDB,我的数据库驻留在 D/:DerbyDB/sample 目录中:

enter image description here

当然这对你来说会有所不同。

关于java - 从位于jdk1.7.0_06的eclipse中的JAVA DB中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12125065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com