我正在尝试连接到我的朋友 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 start
您似乎无法连接到 Oracle 服务器。首先尝试使用 Oracle 的端口远程登录您的 Oracle 服务器。
前任:
telnet <Oracle Serrver IP> 1521
当您:
典型的 Oracle 网络设置包括:
正如其他人指出的那样,(1)数据库需要启动;(2) 监听器需要运行并且你需要知道什么端口;(3) 防火墙需要配置为允许端口上的流量,通常在服务器端。
您的朋友可以通过侦听器(不是本地连接)在他们的系统上使用 ODBC 连接吗?换句话说,您的代码会在他们的系统上运行吗?
扣板执行以下操作:
在连接字符串中使用域名而不是 ip addesss:
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
而不是Class.forName(oracle.jdbc.driver.OracleDriver).newInstance();