Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 378
macmar22 Avatar asked Feb 27 '26 07:02

macmar22


1 Answers

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";
like image 146
Andrei Avatar answered Mar 01 '26 19:03

Andrei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!