Search code examples
javamysqljdbc

java.sql.SQLException: No suitable driver found for jdbc:mysql//127.0.0.1:3306/java Error - JDK 1.8, mysql-connector 8.0.12


I tried searching for a solution but the questions on this website just weren't the answer I'm looking for.

I tried running:

private static final String USERNAME= "root";
private static final String PASSWORD= "root";
private static final String CONN_STRING= "jdbc:mysql//localhost:3306/java";

conn Connection = null;

try{
    conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
    System.out.println("Connected");
} catch (SQLException e){
    System.err.println(e);
}

I've got the 8.0.12 version of both server and connector.


Solution

  • Your JDBC URL should follow jdbc:mysql://localhost/test format as per 7.1 Connecting to MySQL Using the JDBC DriverManager Interface docs.

    You are missing a semicolon after mysql part, it should be

    private static final String CONN_STRING = "jdbc:mysql://localhost:3306/java";