如何连接到 IntelliJ Ultimate 的 LocalHost MySQL 数据库?
How to connect to IntelliJ Ultimate's LocalHost MySQL database?
我转到数据库 > + > 数据源 > MySQL
我的面板如下所示:
这是错误:
[08S01]
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.
java.net.ConnectException: Connection refused: connect.
这是我的连接文件:
package sample;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnection
{
private static Connection connection;
private static final String user = "root";
private static final String password = "root";
private static final String database = "jdbc:mysql://localhost:3306/user";
public static Connection getConnection()
{
if (connection == null)
{
try
{
connection = DriverManager.getConnection(database, user, password);
} catch (SQLException e)
{
e.printStackTrace();
System.out.println("Could not open database.");
System.exit(1);
}
}
return connection;
}
}
我的问题是什么?我尝试搜索其他人尝试过的方法,但其中 none 似乎有效,我不得不为我的整个项目制作多个副本,因为我一直在尝试这些解决方案而无济于事。更具体地说 Solving a "communications link failure" with JDBC and MySQL
我转到数据库 > + > 数据源 > MySQL
我的面板如下所示:
这是错误:
[08S01]
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.
java.net.ConnectException: Connection refused: connect.
这是我的连接文件:
package sample;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnection
{
private static Connection connection;
private static final String user = "root";
private static final String password = "root";
private static final String database = "jdbc:mysql://localhost:3306/user";
public static Connection getConnection()
{
if (connection == null)
{
try
{
connection = DriverManager.getConnection(database, user, password);
} catch (SQLException e)
{
e.printStackTrace();
System.out.println("Could not open database.");
System.exit(1);
}
}
return connection;
}
}
我的问题是什么?我尝试搜索其他人尝试过的方法,但其中 none 似乎有效,我不得不为我的整个项目制作多个副本,因为我一直在尝试这些解决方案而无济于事。更具体地说 Solving a "communications link failure" with JDBC and MySQL