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();
}
}
添加回答
举报