1 回答

TA貢獻1786條經驗 獲得超11個贊
我無法使用 Oracle 數據庫對其進行準確測試,但我知道在建立連接之前必須注冊一個驅動程序。檢查以下代碼,這基本上是您的代碼加上驅動程序注冊。
public static void main(String args[]) throws Exception {
// registration for the driver, it's needed,
// otherwise there will be "no suitable driver found"
Class.forName("oracle.jdbc.driver.OracleDriver");
try (Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@128:23:44:01:12345:pppp_rr", "Test123", "********")) {
if (conn != null) {
System.out.println("Connected to the database!");
} else {
System.out.println("Failed to make connection!");
}
} catch (SQLException e) {
System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}
添加回答
舉報