1

New to JDBC and trying to connect to data base in MySql workbench. Following is the Java code

import java.sql.*;


public class Demo {
    
    public static void main(String[] args) throws Exception
    {   
        String url = "jdbc:mysql://localhost:3306//students?useSSL=false"; 
        String user = "root";
        String password = "root";
        String query = "Select * from students";
        
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection con = DriverManager.getConnection(url, user, password);  
        Statement st = con.createStatement();
        ResultSet rt = st.executeQuery(query);
        
        rt.next();
        String name = rt.getString("stu_name");
        
        System.out.println(name);
        
        st.close();
        con.close();
    }

}

Following is the error being thrown:

Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.

My MySQL workbench version is 8.0.21 with same version for mysql-connector/J Database in workbench

1
  • 1
    Malformed database URL. Remove the second double slash and try again. Commented Aug 24, 2020 at 9:59

1 Answer 1

2

I assume the problem is the double slash (//) in your URL. Try

 String url = "jdbc:mysql://localhost:3306/students?useSSL=false"; 

instead.

Sign up to request clarification or add additional context in comments.

1 Comment

ya, just figured that out 😅, thanks for your help 👍

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.