Java 如何连接IntelliJ Ultimate';是本地主机MySQL数据库吗?

Java 如何连接IntelliJ Ultimate';是本地主机MySQL数据库吗?,java,mysql,database,intellij-idea,connection,Java,Mysql,Database,Intellij Idea,Connection,我去了数据库>+>datasource>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: Con

我去了数据库>+>datasource>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;
    }

}
我有什么问题?我试着搜索其他人尝试过的东西,但似乎没有一个奏效,我不得不复制我整个项目的几份副本,因为我一直在尝试这些解决方案,但都没有成功。更具体地说


也许我遗漏了一些更明显的东西,我只是看不到,任何线索帮助,提前谢谢。

我想你的程序没有运行,所以你去配置Intelij中的某个数据源以与数据库建立连接

如果是这样的话

  • 无法访问您的数据库。检查它是否正在运行,以及此处提供的所有信息是否正确

  • 您不需要为程序运行设置InteliJ数据源。这仅适用于您使用Intelij执行sql脚本。它与您使用java开发的连接到该数据库的程序无关


  • 您需要有MySQL服务器,并且能够从其他应用程序连接到它。

    您是否让服务器在3306端口上运行和侦听?脸上布满了皱纹。您可以使用任何其他工具连接到此服务器吗?有防火墙可以阻止连接吗?@CrazyCoder,假设它没有运行,我如何让服务器在端口3306上运行?你有没有试着遵循和?@CrazyCoder dang,我没有这样做。我遵循了这个教程,我想我所要做的就是:@CrazyCoder谢谢,我会查看它并给它一个tryno程序,它以前运行得很好。我只是想添加一个数据库,我查阅了一份关于如何添加的教程,他们说添加数据源和mysql,就是这样。没有提到连接文件?你打算让数据库从该连接文件运行吗?是的,这就是我的意图,我厌倦了youtube教程:没有数据库不会以这种方式启动。这是一个不同的程序,你必须安装在你的电脑,执行和配置。与java和Intelij无关