Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Malformed database URL, failed to parse the main URL sections

Tags:

java

mysql

package miniproject;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Mysql_connection {

    private Connection con=null;
    private Statement st=null;
    private ResultSet res=null;
    public Mysql_connection() {
    try{        
            //Class.forName("com.mysql.jdbc.Driver");

            con=DriverManager.getConnection("jdbc:mysql:‪//localhost:3306/miniprojectdb","root","");
            st=con.createStatement();

    }catch(SQLException e)
    {
        System.out.println("SQLException: "+ e.getMessage());
        System.out.println("SQLState: "+ e.getSQLState());
        System.out.println("VendorError"+ e.getErrorCode());   
    }
    }
    public void Data(){
    try{        
        String query="select * from produit";
        res=st.executeQuery(query);
        System.out.println("========================="); 
        while(res.next()){
            int a=res.getInt(1);
            String b=res.getString(2);
            int c=res.getInt(3);
            System.out.println("ProdID:"+a+" "+"ProdNom:"+b+" "+"Prix/Tonne:"+c);
        }
    }catch(Exception e){ 
        System.out.println(e);  
    }   
    }

}

I'm getting this Error:

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

SQLState: 08001

VendorError0

I'm using this (C:\Users\ABDOU NASSER\Desktop\mysql-connector-java-8.0.11\mysql-connector-java-8.0.11.jar) with the last eclipse version 2018 and as database XAMPP (MySQL)

enter image description here enter image description here enter image description here

like image 412
Abdou Nasser Chan Avatar asked May 12 '18 23:05

Abdou Nasser Chan


1 Answers

There's an invisible character between mysql: and //localhost in your JDBC URL. You can check it here:

https://www.soscisurvey.de/tools/view-chars.php

This shows the string as:

jdbc:mysql:‪U+202A//localhost:3306/miniprojectdb

This U+202A character is LEFT-TO-RIGHT EMBEDDING.

like image 138
lexicore Avatar answered Oct 15 '22 17:10

lexicore