PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 21, 2022

[FIXED] Why is my MySql JDBC Driver not connecting?

 April 21, 2022     connection, database, java, mysql     No comments   

Issue

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



Answered By - Lukas Scholz
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing