Solution to SQLException: No suitable driver found for jdbc:mysql

Just a quick fix.

Instead of:

Connection con = null;
 
String url = "jdbc:mysql://localhost:3306/mysql";
String user = "user";
String password = "password";
con = DriverManager.getConnection(url, user, password);

You should have:

Connection con = null;
 
String url = "jdbc:mysql://localhost:3306/mysql";
String user = "user";
String password = "password";
 
try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
    System.err.println(ex.getMessage());
}
con = DriverManager.getConnection(url, user, password);

If you still get an error:

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/mysql

Check in you configuration, if you have connected to a database:

 

If so, you must add a package into your NB project:

Right click on a project -> Properties -> Libraries -> Add Library -> MySQL JDBC Driver

[Total: 0    Average: 0/5]