我的java应用程序正在使用odbc14来连接oracle 11g。它正在完美地重启我的linux服务器。
现在我的应用程序只使用直接IP地址而不是主机名。
我不知道在我的服务器中重置了什么设置。 现在我在使用主机名时遇到异常。
java.sql.SQLException:Io异常:网络适配器不能 建立连接
代码:
String IP = "Server099";
String port = "1521";
String DBNAME= "PGDB";
String mcS_UserName="UserName";
String mcS_Password="Password";
String JDBC_DRIVER="oracle.jdbc.driver.OracleDriver";
Connection conn;
String DB_URL= "jdbc:oracle:thin:@"+IP+":"+port+":"+DBNAME;
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL,mcS_UserName,mcS_Password);
输出tnsping:
]$ tnsping Server099
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 01-MAR-2016 14:02:54
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
/home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/sqlnet.ora
Used EZCONNECT adapter to resolve the alias
Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS= (PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=10.0.0.99)(PORT=1521)))
好(0毫秒)
堆栈跟踪:
2016-03-01 14:17:37,496 ERROR ussd.DB_Conn.DBCon:110 Error in connecting Primary DB java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
答案 0 :(得分:0)
您是否通过tnsping命令检查服务器地址?
tnsping net_service_name
可能地址已更改或数据库未启动。
答案 1 :(得分:0)
尝试此操作以确保所有10次连接尝试都成功,以确保不存在网络问题: ] $ tnsping Server099 10