Reputation: 147
I went to Database > + > Data Source > MySQL
Here's what my panel looks like:
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
Upvotes: 1
Views: 1472
Reputation: 401897
You need to have MySQL server installed and running to be able to connect to it from the other apps.
Upvotes: 1
Reputation: 18909
I suppose that your program did not run and so you went to configure some datasource in Intelij to make a connection with your Database.
If that is the case then
Your db is not reachable. Check if it is running and if all information provided here is correctly.
You don't need to set a InteliJ Datasource for your program to run. That is only for you to execute sql scripts using Intelij. It has nothing to do with some program that you develop using java which connects to that database.
Upvotes: 1