我正在尝试使用以下代码连接到Java中的远程oracle数据库服务器:
public static Connection getConexionOracle () {
Connection con = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@//oracle.vital.com.mx:1521:XE","username","password");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
我使用的是Oracle g11 Releas 2,我已经在构建路径中包含了ojdbc.jar。 尝试建立连接时,出现以下堆栈跟踪错误:
java.sql.SQLException: Error de E/S: The Network Adapter could not establish the connection
[java] at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:458)
[java] at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:546)
[java] at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:236)
[java] at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
[java] at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
[java] at java.sql.DriverManager.getConnection(Unknown Source)
[java] at java.sql.DriverManager.getConnection(Unknown Source)
[java] at vital.tde.general.Conexion.getConexionOracle(Conexion.java:22)
[java] at vital.tde.general.Prueba.doGet(Prueba.java:35)
[java] at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
[java] at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
[java] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
[java] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
[java] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
[java] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
[java] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
[java] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
[java] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
[java] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
[java] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
[java] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
[java] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
[java] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
[java] at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
[java] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[java] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[java] at java.lang.Thread.run(Unknown Source)
[java] Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
[java] at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:392)
[java] at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:434)
[java] at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:687)
[java] at oracle.net.ns.NSProtocol.connect(NSProtocol.java:247)
[java] at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1102)
[java] at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:320)
[java] ... 26 more
[java] Caused by: java.net.UnknownHostException: //oracle.vital.com.mx
[java] at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
[java] at java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)
[java] at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
[java] at java.net.InetAddress.getAllByName0(Unknown Source)
[java] at java.net.InetAddress.getAllByName(Unknown Source)
[java] at java.net.InetAddress.getAllByName(Unknown Source)
[java] at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:117)
[java] at oracle.net.nt.ConnOption.connect(ConnOption.java:133)
[java] at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:370)
[java] ... 31 more
我已经尝试了以下操作,但仍然收到错误:
您对此问题建议采用哪种解决方案?我非常感谢你的帮助。
答案 0 :(得分:2)
[java] Caused by: java.net.UnknownHostException: //oracle.vital.com.mx
尝试删除连接字符串中的“//”。
答案 1 :(得分:1)
我有同样的问题,我试试这个并且它有效:
- 从Oracle服务器计算机执行此命令 $ lsnrctl服务 它为您提供了无差别的服务。
- 在java的url字符串连接上放置外部服务的“HOST”和“PORT”的值(此服务的名称类似于“XDB.your.domain”)。
祝你好运!PS:对不起我的英文。
我看到你解决了连接问题。好吧,如果将来你有一些远程连接问题,你有我的答案。