-1

I have this error jdbc : I tried so far (build path, jar folder into /bin/ folder and 2 others ) but still nothing

You may say it's duplicate (but I tried all the solution I saw so far 4 and i still have the same error" enter image description here

java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at Main.main(Main.java:13)

This is the code I am using :

import java.sql.*;

public class Main {

public static void main(String args[]) throws SQLException {

    String host = "jdbc:mysql://localhost:3306/lorann?autoReconnect=true&useSSL=false&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
    String uName = "root";
    String uPass= "";

    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
    e.printStackTrace();
}

    Connection co = DriverManager.getConnection(host,uName,uPass);
    Statement stmt = co.createStatement();


    ResultSet rs = stmt.executeQuery("SELECT contenu FROM niveau");
    @SuppressWarnings("unused")
    ResultSetMetaData rsm = rs.getMetaData();



    while(rs.next()) {
        System.out.println(rs.getString("contenu"));
    }

}}
Hash
  • 4,647
  • 5
  • 21
  • 39
Danny boon
  • 43
  • 4

1 Answers1

0

I found the solution : instead of using this :

com.mysql.cj.jdbc.Driver

we use :

com.mysql.jdbc.Driver

but i am not sure it's the solution because the expected console print : is not showing off

ClassNotFoundException with com.mysql.cj.jdbc.Driver, MySQL Connector and IntelliJ IDEA

Danny boon
  • 43
  • 4