1 回答

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊
我無(wú)法使用 Oracle 數(shù)據(jù)庫(kù)對(duì)其進(jìn)行準(zhǔn)確測(cè)試,但我知道在建立連接之前必須注冊(cè)一個(gè)驅(qū)動(dòng)程序。檢查以下代碼,這基本上是您的代碼加上驅(qū)動(dòng)程序注冊(cè)。
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();
}
}
添加回答
舉報(bào)