我正在嘗試爲實踐設置遠程Derby數據庫。下面的代碼工作沒有問題,每當我訪問我的硬盤的DB:設置遠程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 。代碼停止工作,就好像它甚至無法看到數據庫。我錯過了什麼?
「沒有找到合適的驅動程序」指的是德比類是不是在你的CLASSPATH。這裏有一些文檔:http://db.apache.org/derby/docs/10.13/getstart/tgs26250.html –
@Bryan Pendleton事情是,當我訪問位於我的硬盤上的數據庫時,連接正常工作,這意味着CLASSPATH變量設置正確。不起作用的是與我上傳到我的網站的同一個數據庫副本的連接。我懷疑dbPath var有什麼問題,因爲用'xyz'等任意名稱替換'derbyDB'會生成相同的SQLException ... –
如果數據庫位於另一臺機器上,則必須在該機器上運行Derby Network Server爲該機器提供客戶端服務器請求。嘗試通過我在之前的評論中鏈接到的教程工作。 –