小编Die*_*iez的帖子

MySQLNonTransientConnectionException:无法创建与数据库服务器的连接.尝试重新连接3次.放弃

我无法连接到我的数据库.我认为有一个我不知道的地方,需要改变.我在这里有一些非常基本的代码:

public static void main(String[] args)
{
    try
    {
        Connection con = DriverManager.getConnection("jdbc:mysql://IP:3306/TABLENAME?autoReconnect=true","USERNAME", "PASSWORD");
        con.close();
    }

    catch(Exception e)
    {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

显然有登录信息.它会导致此错误:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

Caused by: 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.

Caused by: java.net.ConnectException: Connection refused
Run Code Online (Sandbox Code Playgroud)

我已经浏览了大约10个关于同一问题的不同帖子,并尝试了他们的解决方案,仍然无法让它工作.

java mysql database-connection

7
推荐指数
1
解决办法
6万
查看次数

标签 统计

database-connection ×1

java ×1

mysql ×1