尝试通过 Java 连接到 Oracle 数据库时,我随机收到“IO 错误:网络适配器无法建立连接”。有时我必须运行我的应用程序几次才能停止抛出错误。
// initializes database connection
private static Connection initializeDatabaseConnection(Properties prop) {
System.setProperty("oracle.net.tns_admin", prop.getProperty("tnsLocation"));
try {
Class.forName("oracle.jdbc.OracleDriver");
}
catch (ClassNotFoundException ex)
{
System.out.println(ex.getMessage());
}
String dbURL = "jdbc:oracle:thin:@" + prop.getProperty("serviceName");
String username = prop.getProperty("username");
String password = prop.getProperty("password");
Connection conn = null;
try {
conn = DriverManager.getConnection(dbURL, username, password);
}
catch (SQLException ex)
{
System.out.println("Error initializing database connection. " + ex.getMessage());
System.exit(1);
}
return conn;
}
关于它为什么随机抛出该错误的任何想法?我正在使用带有 ojdbc6.jar 驱动程序的 JDK 1.7。