简体   繁体   English

java.net.UnknownHostException:&lt; <hostname> &gt;:未知错误

[英]java.net.UnknownHostException: <<hostname>> : unknown error

I'm trying to establish Oracle DB connection from the application which runs on an EC2 instance of AWS. 我正在尝试从在AWS的EC2实例上运行的应用程序建立Oracle DB连接。 Oracle DB is in on-prem server. Oracle DB在本地服务器中。 Firewall has been opened and I'm able to telnet to the SCAN and VIP hosts of that DB from my EC2 instance. 防火墙已打开,我能够从我的EC2实例远程登录到该数据库的SCAN和VIP主机。 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 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))))`

Are you using java 8 ? 您正在使用Java 8吗? If so then probably it's related to this bug 如果是这样,则可能与该错误有关

Java 7 or 9 would probably give you a more useful error message instead of "unknown error" (eg possibly "Name or service not known") Java 7或9可能会给您更有用的错误消息,而不是“未知错误”(例如,“名称或服务未知”)

Apart from that, did you try a tnsping from the host you're trying to connect from ? 除此之外,您是否尝试过尝试与之连接的主机进行tnsping?

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 : 另外,按照以下在Oracle驱动程序文档中的说明 ,在jdbc URL中使用tnsnames条目时,应使用OCI驱动程序,如下所示:

Note that you can also specify the database by a TNSNAMES entry. 请注意,您还可以通过TNSNAMES条目指定数据库。 You can find the available TNSNAMES entries listed in the file tnsnames.ora on the client computer from which you are connecting. 您可以在要连接的客户端计算机上的文件tnsnames.ora中找到可用的TNSNAMES条目。 For example, if you want to connect to the database on host myhost as user scott with password tiger that has a TNSNAMES entry of MyHostString, enter: 例如,如果要以密码为“ tiger”的用户scott身份连接到主机myhost上的数据库,该密码具有MyHostString的TNSNAMES条目,请输入:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM