Cara menggunakan mysql-connector-java-8.0.28.jar download

26

New! Save questions or answers and organize your favorite content.
Learn more.

I'm new in Java, and I need to establish a connection to a MySQL server (local), I have add the libraries in Intellij idea but it seems not work, the IDE can't find the class i think... I become crazy I'm searching since two hours... I come from visual studio/c# dev environment and i think that i should miss something...

Here you can have a pic from my IDE and the simple code that I wanted use. You can also deduce that I have import the jar in my project (mysql-jdbc).

IDE pic

Edit : here is the code, the comment show where the error appear :

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
import org.*;
import com.mysql.jdbc.Driver;


public class JdbcLogin {
    public String Login;
    public String MotDePasse;
    private boolean Logged = false;

    public void StartBdd(){
        String driverName = "com.mysql.jdbc.Driver";
        Class.forName(driverName); // here is the ClassNotFoundException

        String serverName = "localhost";
        String mydatabase = "suptodo";
        String url = "jdbc:mysql://" + serverName + "/" + mydatabase;

        String username = "root";
        String password = "azerty";
        Connection connection = DriverManager.getConnection(url, username, password);
    }
}

asked Jun 4, 2015 at 18:50

Cara menggunakan mysql-connector-java-8.0.28.jar download

NimpNimp

4411 gold badge4 silver badges15 bronze badges

6

It's easy to configure. First just open the IntelliJ IDE and follow this simple step:

File->Project Structure->Libraries

Then click on the plus(+) sign and select From Maven....

Cara menggunakan mysql-connector-java-8.0.28.jar download

After you'll get a search box. There you should put:

mysql:mysql-connector-java:5.1.40

Cara menggunakan mysql-connector-java-8.0.28.jar download

This will solve the issue.

Cara menggunakan mysql-connector-java-8.0.28.jar download

answered Apr 2, 2018 at 6:14

Cara menggunakan mysql-connector-java-8.0.28.jar download

Pronab RoyPronab Roy

1,0181 gold badge14 silver badges18 bronze badges

1

You have to add 'mysql:mysql-connector-java:5.1.40' from maven or add it as java library as shown:

Cara menggunakan mysql-connector-java-8.0.28.jar download

answered Nov 30, 2016 at 2:41

Cara menggunakan mysql-connector-java-8.0.28.jar download

Solution#1:Drop the mysql-connector-java-version-bin.jar file to your project, right click on it, select "Add as library".

Solution#2:Build and run with command line, for example(Windows)

  • javac yourclassname
  • java -cp".;mysql-connector-java-version-bin.jar" yourclassname

answered Jun 1, 2017 at 8:59

Cara menggunakan mysql-connector-java-8.0.28.jar download

renzherlrenzherl

1511 silver badge3 bronze badges

1

If it says time zone unrecognized you can add this piece of code to the URL:

Connection connection = DriverManager.getConnection("jdbc:mysql://localhost?useTimezone=true&serverTimezone=UTC","USER-NAME","PASSWORD");

Don't forget to wrap it with a try-catch.

Cara menggunakan mysql-connector-java-8.0.28.jar download

answered Sep 2, 2019 at 17:01

Cara menggunakan mysql-connector-java-8.0.28.jar download

As an Update this will work with mysql:mysql-connector-java:8.0.18 as the other version will generate a new problem and won't connect to the database server.

answered Jan 8, 2021 at 6:36

Cara menggunakan mysql-connector-java-8.0.28.jar download