Search code examples
javamysqldatabaseconnection

Why is my MySql JDBC Driver not connecting?


I am new to MySql and I want to connect to my database from my Java project.

I already downloaded the JDBC Driver (https://dev.mysql.com/downloads/connector/j/). I had some difficulties with putting it in my build path, but I think I got it to work.

Now when I try to connect to the database I get a lot of errors. I get 2 times "Communication link failure" and then "Connection refused".

I don't have any idea what I did wrong.

This is my Build Path: BUild Path

This is my Code:

package net.codejava;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;

public class MySQLTest {

    public static void main(String[] args) {

            String url = "jdbc:mysql://localhost:3006/namdb";
            String user = "root";
            String password = "xxxxx";
            
            try {
                Connection connection  = DriverManager.getConnection(url, user, password);
                System.out.println("Connected");
            } catch (SQLException e) {
                
                System.out.println("Oops");
                e.printStackTrace();
            }
            
            
    }

}

Maybe someone can give me advise on how to get this thing running... Thanks!


Solution

  • I solved it by sepcifying the timezone: String url = "jdbc:mysql://localhost:3306/namdb?useSSL=false&serverTimezone=Europe/Warsaw";