Skip to content
Advertisement

How to connect to IntelliJ Ultimate’s LocalHost MySQL database?

I went to Database > + > Data Source > MySQL

Here’s what my panel looks like: enter image description here

This is the error:

[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.

and here’s my connection file:

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;
    }

}

What could be my problem? I tried searching up for what others have tried but none of them seemed to work and I had to make several copies of my entire project because I kept messing things up trying those solutions to no avail. More specifically Solving a “communications link failure” with JDBC and MySQL

Advertisement

Answer

You need to have MySQL server installed and running to be able to connect to it from the other apps.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement