gpt4 book ai didi

java - 未知主机异常 : while connecting to database server

转载 作者:行者123 更新时间:2023-11-29 17:53:32 24 4
gpt4 key购买 nike

我正在尝试在 1nd1.com 上托管 MySQL 数据库。我创建了一个包含几个表的数据库。从 java 应用程序连接到 1and1 数据库时出现以下错误。

当使用“ping hostname”命令从命令提示符执行 ping 操作时,响应失败。

有什么方法可以从java程序连接到该主机吗?

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION **

java.net.UnknownHostException
MESSAGE: db726853948.db.1and1.com

STACKTRACE:

java.net.UnknownHostException: db726853948.db.1and1.com
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302)
at java.net.InetAddress.getAllByName0(InetAddress.java:1255)
at java.net.InetAddress.getAllByName(InetAddress.java:1171)
at java.net.InetAddress.getAllByName(InetAddress.java:1105)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:246)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at Contct.insertDetails(Contct.java:11)
at Contct.main(Contct.java:28)

** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.

最佳答案

尝试将主机名添加到主机文件

例如:

your_host_ip(122.2.2.1)     hostname(db726853948.db.1and1.com)

关于java - 未知主机异常 : while connecting to database server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49084108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com