我测试数据库连接的代码: -
public static void main(String args[])
throws ClassNotFoundException,SQLException,
ConnectException
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connectioncon=DriverManager.getConnection
("jdbc:oracle:thin:UNAME/PSWD@//
hostname:1521/servicename");
con.close();
}
错误: -
SQLState(08006) vendor code(17002)
java.sql.SQLRecoverableException: IO Error:
The Network Adapter could not establish the connection
at oracle.jdbc.driver.SQLStateMapping.newSQLException
(SQLStateMapping.java:100)
at
oracle.jdbc.driver.DatabaseError.newSQLException
(DatabaseError.java:144)
at oracle.jdbc.driver.DatabaseError.createSqlException
(DatabaseError.java:191)
at oracle.jdbc.driver.DatabaseError.createSqlException
(DatabaseError.java:258)
at oracle.jdbc.driver.DatabaseError.createSqlException
(DatabaseError.java:482)
at
oracle.jdbc.driver.T4CConnection.logon
(T4CConnection.java:488)
at
oracle.jdbc.driver.PhysicalConnection.<init>
(PhysicalConnection.java:553)
at
oracle.jdbc.driver.T4CConnection.<init>
(T4CConnection.java:254)
at oracle.jdbc.driver.T4CDriverExtension.getConnection
(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect
(OracleDriver.java:528)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at webdriver.TlgDB.main(TlgDB.java:20)
SQLState(99999) vendor code(17430)
java.sql.SQLException: Must be logged on to server
at oracle.jdbc.driver.SQLStateMapping.newSQLException
(SQLStateMapping.java:71)
at oracle.jdbc.driver.DatabaseError.newSQLException
(DatabaseError.java:144)
at oracle.jdbc.driver.DatabaseError.createSqlException
(DatabaseError.java:191)
at oracle.jdbc.driver.DatabaseError.createSqlException
(DatabaseError.java:258)
at oracle.jdbc.driver.DatabaseError.createSqlException
(DatabaseError.java:266)
at oracle.jdbc.driver.DatabaseError.createSqlException
(DatabaseError.java:413)
at oracle.jdbc.driver.T4CConnection.assertLoggedOn
(T4CConnection.java:3828)
at oracle.jdbc.driver.T4CConnection.logoff
(T4CConnection.java:569)
at oracle.jdbc.driver.PhysicalConnection.<init>
(PhysicalConnection.java:662)
at oracle.jdbc.driver.T4CConnection.<init>
(T4CConnection.java:254)
at oracle.jdbc.driver.T4CDriverExtension.getConnection
(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect
(OracleDriver.java:528)at java.sql.DriverManager.getConnection
(Unknown Source)at java.sql.DriverManager.getConnection
(Unknown Source)at webdriver.TlgDB.main(TlgDB.java:20)
getConnection failed: java.sql.SQLRecoverableException:
IO Error: The Network Adapter could not establish the connection
Exception in thread "main" java.sql.SQLRecoverableException:
IO Error: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon
(T4CConnection.java:489)
at oracle.jdbc.driver.PhysicalConnection.<init>
(PhysicalConnection.java:553)
at oracle.jdbc.driver.T4CConnection.<init>
(T4CConnection.java:254)
at oracle.jdbc.driver.T4CDriverExtension.getConnection
(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect
(OracleDriver.java:528)at java.sql.DriverManager.getConnection
(Unknown Source)at java.sql.DriverManager.getConnection
(Unknown Source)
at webdriver.TlgDB.main(TlgDB.java:20)
Caused by: oracle.net.ns.NetException: The Network Adapter could
not establish the connection
at oracle.net.nt.ConnStrategy.execute
(ConnStrategy.java:439)
at oracle.net.resolver.AddrResolution.resolveAndExecute
(AddrResolution.java:454)
at oracle.net.ns.NSProtocol.establishConnection
(NSProtocol.java:693)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:347)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1140)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:340)
... 7 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:149)
at oracle.net.nt.ConnOption.connect(ConnOption.java:133)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:405)
... 12 more
到目前为止尝试了以下步骤,但还没有运气: -
2.必须登录到服务器 - 我开始toad并连接到数据库但面临同样的问题。
3. tnsping hostname
表示'tnsping'
未被识别为内部或外部命令,可操作程序或批处理文件。
控制台中的防火墙设置已关闭。
尝试将连接字符串用作: -
String url = "jdbc:oracle:thin:@
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST=hostname)(PORT=1521))"+
"(CONNECT_DATA=(SERVER=DEDICATED)
(SERVICE_NAME=servicename)))";
并将此url
传递给getConnection
obj,但仍面临同样的问题。
任何建议都会受到赞赏吗?