【发布时间】:2017-02-03 02:06:30
【问题描述】:
我正在通过 000WebHosting.com 运行数据库。当我尝试连接到我的数据库时,我收到以下错误:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
这是我的代码:
String url = "jdbc:mysql://" + "mysql2.000webhost.com/";
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(url + "DB_NAME", userName, passWord);
}
catch (InstantiationException | IllegalAccessException | SQLException e)
{
System.out.println(e);
}
conn 行上继续出现异常。
我做错了什么?
【问题讨论】:
-
您实际上没有连接。检查您的数据库 url 并确保它是正确的。
-
我非常怀疑该地址上的端口是否打开,等待您的连接,或者它已被授权用于数据库
标签: java mysql database web-hosting