gpt4 book ai didi

java - 设置远程 Derby DB : "No suitable driver found" error

转载 作者:行者123 更新时间:2023-12-02 13:28:52 24 4
gpt4 key购买 nike

我正在尝试设置一个远程 Derby 数据库以供练习。每当我访问硬盘驱动器上的数据库时,以下代码都可以正常工作:

class Test{
public static void main(String[] args) {
String protocol = "jdbc:derby:";
// String dbPath = "C:/Java_Practice/derbyDB"; // this dbPath works...
String dbPath = "//108.167.141.127/derbyDB"; // and this one doesn't
String url = protocol + dbPath;
try( Connection conn = DriverManager.getConnection(url) )
{
System.out.println(conn);
}
catch(SQLException e){
System.out.println(e.getMessage());
}
}
}

然后,我将整个 derbyDB 目录上传到我的 Hostgator 托管的网站,通过 ping 服务器获取其 IP,并相应地编辑 dbPath var。该代码停止工作,就好像它甚至看不到数据库一样。我错过了什么?

最佳答案

看起来您的驱动程序类未加载。尝试在调用 DriverManager.getConnection 之前加载它,看看是否有效。

String driver = "org.apache.derby.jdbc.ClientDriver";
Class.forName(driver).newInstance();
String protocol = "jdbc:derby:";
String dbPath = "//108.167.141.127/derbyDB"+";create=true";
String url = protocol + dbPath;
Connection conn = DriverManager.getConnection(url);

关于java - 设置远程 Derby DB : "No suitable driver found" error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43280681/

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