macmar22
macmar22

Reputation: 31

Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException

Here is my code:

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

public class TestJdbc {
public static void main(String[] args) {        

    String jdbcUrl = "jdbc:mysql://localhost:3306?hb_student_tracker?useSSL=false&serverTimezone=UTC";
    String user = "hbstudent";
    String pass = "hbstudent";
    try {
        System.out.println("Conectiong to database: "+jdbcUrl);
        Connection myConn =
                DriverManager.getConnection(jdbcUrl,user,pass);
        System.out.println("Connection succesful!!!");

    } 
    catch(Exception ex) {
        ex.printStackTrace();
    }
}

}

It fails with the following error:

Conectiong to database: 
jdbc:mysql://localhost:3306?hbstudent?useSSL=false&serverTimezone=UTC 
java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: 
com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, 
failed to parse the connection string near '?useSSL=false&serverTimezone=UTC'.

What am I doing wrong?

Upvotes: 3

Views: 13798

Answers (1)

Andrei
Andrei

Reputation: 21

You better check the documentation.

Probably, the problem is in URL. It should be a slash after port and before the database name.

String jdbcUrl = "jdbc:mysql://localhost:3306/hb_student_tracker?useSSL=false&serverTimezone=UTC";

Upvotes: 2

Related Questions