I'm setting up a new database connection but ended with "java.sql.SQLException: No suitable driver found for jdbc:mysql//localhost:3306/gaming_site" error! Please help me to fix this!
I'm using mysql v8.0 Therefore I added mysql connector v8.0.12 in java build path's libraries
Code for establishing database connection:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnection {
public static Connection getConnection() throws ClassNotFoundException, SQLException {
String dbDriver = "com.mysql.jdbc.Driver";
String dbURL = "jdbc:mysql//localhost:3306/gaming_site";
String dbUserName = "root";
String dbPassword = "root";
Class.forName(dbDriver);
Connection con = DriverManager.getConnection(dbURL,dbUserName,dbPassword);
return con;
}
}
You're missing a colon in the JDBC URL:
jdbc:mysql://localhost:3306/gaming_site
^
Add this.
See the syntax at https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-jdbc-url-format.html