Die*_*iez 7 java mysql database-connection
我无法连接到我的数据库.我认为有一个我不知道的地方,需要改变.我在这里有一些非常基本的代码:
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个关于同一问题的不同帖子,并尝试了他们的解决方案,仍然无法让它工作.
当 MySQL 服务未运行并且您尝试连接到 mysql 数据库时,会出现此问题。
要在 Windows 中解决此问题,
开始 >> 输入“服务”并将其打开。
找到 MySQL 服务。可能名为 MySQLxx。xx 是版本。
例如。MySQL56、MySQL57 等
启动服务,然后尝试连接到数据库。
| 归档时间: |
|
| 查看次数: |
58021 次 |
| 最近记录: |