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

标签 java mysql

我正在尝试在 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/

相关文章:

java - Commons Math : The Apache Commons Mathematics Library 的内存要求

java - 为什么从 https 切换到 http 时我的 session ID (JSESSIONID) 会发生变化? java jsf

java - java "Context"类的用途是什么?

java - 设置Spring Boot可执行jar的工作目录

mysql - 插入 XML 数据

mysql + 一个字段中的所有数字求和

php - 查询 Percona 集群节点的当前负载

java - 通过在 Spring-MVC Hibernate 应用程序中进行缓存来缩短页面加载时间

mysql - 我想获取所有大于数据库中给定日期的记录

mysql - 使用 UNION 在多个表中进行选择