java.net.UnknownHostException:<<主机名>> : 未知错误 [英] java.net.UnknownHostException: <<hostname>> : unknown error

查看:159
本文介绍了java.net.UnknownHostException:<<主机名>> : 未知错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从在AWS的EC2实例上运行的应用程序建立Oracle DB连接. Oracle DB在本地服务器中.防火墙已打开,我能够从我的EC2实例远程登录到该数据库的SCAN和VIP主机.但是,仍然出现以下异常:

I'm trying to establish Oracle DB connection from the application which runs on an EC2 instance of AWS. Oracle DB is in on-prem server. Firewall has been opened and I'm able to telnet to the SCAN and VIP hosts of that DB from my EC2 instance. But, still I'm getting the below exception:

Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:392) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:434) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:687) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:343) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1102) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:320) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
... 239 common frames omitted
Caused by: java.net.UnknownHostException: <<hostname>>: unknown error
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) ~[na:1.8.0_40-internal]
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907) ~[na:1.8.0_40-internal]
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302) ~[na:1.8.0_40-internal]
at java.net.InetAddress.getAllByName0(InetAddress.java:1255) ~[na:1.8.0_40-internal]
at java.net.InetAddress.getAllByName(InetAddress.java:1171) ~[na:1.8.0_40-internal]
at java.net.InetAddress.getAllByName(InetAddress.java:1105) ~[na:1.8.0_40-internal]
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:117) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.net.nt.ConnOption.connect(ConnOption.java:133) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:370) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]

JDBC URL:

jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)
(HOST = <<IP address of the host>>)(PORT = 1590)))(LOAD_BALANCE = yes)
(CONNECT_DATA =(SERVICE_NAME = <<example.service.com>>)(FAILOVER_MODE =(TYPE = SELECT)
(METHOD = BASIC))))`

推荐答案

您是否正在使用Java 8?如果是这样,则可能与此错误

Are you using java 8 ? If so then probably it's related to this bug

Java 7或9可能会给您更有用的错误消息,而不是未知错误"(例如,名称或服务未知")

Java 7 or 9 would probably give you a more useful error message instead of "unknown error" (eg possibly "Name or service not known")

除此之外,您是否尝试过从尝试连接的主机进行tnsping?

Apart from that, did you try a tnsping from the host you're trying to connect from ?

也按照中的以下内容进行操作Oracle驱动程序文档,在jdbc URL中使用tnsnames条目时,应使用OCI驱动程序,如下所示:

Also as per the below in the Oracle driver documentation when using a tnsnames entry in the jdbc URL it should be as below, using OCI driver :

请注意,您还可以通过TNSNAMES条目指定数据库.您可以在要连接的客户端计算机上的文件tnsnames.ora中找到可用的TNSNAMES条目.例如,如果要使用密码为"tiger"的用户scott以主机scott的身份连接到主机myhost上的数据库,该密码具有MyHostString的TNSNAMES条目,请输入:

Connection conn = DriverManager.getConnection
  ("jdbc:oracle:oci8:@MyHostString","scott","tiger");

这篇关于java.net.UnknownHostException:&lt;&lt;主机名&gt;&gt; : 未知错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆