我正在尝试连接到我的朋友Oracle服务器。 但是,虽然连接我得到错误,请帮助…..
JDBC代码
Class.forName(oracle.jdbc.driver.OracleDriver).newInstance(); conn=DriverManager.getConnection(jdbc:oracle:thin:@<IPaddress>:<SID>,userName,password); conn.close();
错误信息
java.sql.SQLException: The Network Adapter could not establish the connection at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at com.wipro.sample.min.main(min.java:28) Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:359) at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422) at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:672) at oracle.net.ns.NSProtocol.connect(NSProtocol.java:237) at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301) ... 7 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddress(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:141) at oracle.net.nt.ConnOption.connect(ConnOption.java:123) at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:337) ... 12 more
看起来像oracle服务器不听…
连接到oracle所在的机器
运行su – oracle
lsnrctl状态
是列表器不活动,然后做lsnrctl启动
看来你不能连接到Oracle服务器。 首先尝试使用Oracle的端口远程login您的Oracle服务器。
例如: telnet <Oracle Serrver IP> 1521
您可能会遇到以下错误:
典型的Oraclenetworking设置包括:
正如其他人所指出的,(1)数据库需要提高; (2)听众需要运行,你需要知道什么端口; (3)需要configuration防火墙以允许端口上的stream量,通常在服务器端。
你的朋友可以通过监听器(不是本地连接)在他们的系统上使用ODBC连接吗? 换句话说,你的代码是否会在他们的系统上运行?
Gusset做以下事情:
在连接string中使用域名而不是ip addesss:
conn=DriverManager.getConnection(jdbc:oracle:thin:@<IPaddress>:<SID>,userName,password); conn=DriverManager.getConnection(jdbc:oracle:thin:@<domain Name>:<SID>,userName,password);
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
而不是Class.forName(oracle.jdbc.driver.OracleDriver).newInstance();