0

我正在尝试使用以下代码连接到 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

我已经尝试了以下方法,但仍然出现错误:

  1. Ping oracle.vital.com.mx(获得响应)
  2. Telnet oracle.vital.com.mx 1521(获得响应)
  3. 禁用服务器防火墙

您对这个问题有什么建议?我将衷心感谢您的帮助。

4

2 回答 2

2
 [java] Caused by: java.net.UnknownHostException: //oracle.vital.com.mx

尝试删除连接字符串中的“//”。

于 2012-06-22T22:00:03.390 回答
1

我有同样的问题,我试试这个并且它有效:

-- 从您的 Oracle 服务器机器 $lsnrctl services 执行此命令,它为您提供可分配的服务。

-- 将外部服务的“HOST”和“PORT”的值(该服务的名称类似于“XDB.your.domain”)放在你的java url字符串连接上。

祝你好运!

PS:对不起我的英语。

我看到你解决了连接问题。好吧,如果将来您在远程连接方面遇到问题,您有我的答案。

于 2012-06-28T14:48:09.497 回答