0

So I have downloaded the MySQL Workbench, sql connector and the server. I am following the steps on youtube but when I tried to run mine I get this error:

java.sql.SQLException: No suitable driver found for jdbc:mysql:localhost:3306/staffs
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
    at Controllers.Database.connect(Database.java:18)
    at Controllers.Main.start(Main.java:29)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:474)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:447)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:446)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:831)

I followed all the steps but I still get an error.

This is the connection method:

package Controllers;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Database {

    Connection db = null;

    String URL = "jdbc:mysql:localhost:3306/staffs";
    String root = "root";
    String password = "";

    public void connect(){
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
            db = DriverManager.getConnection(URL,root,password);
        }catch (ClassNotFoundException  | SQLException e){
            e.printStackTrace();
        }

    }
}
akolangto
  • 33
  • 1
  • 6
  • maybe this [link](https://stackoverflow.com/questions/5556664/how-to-fix-no-suitable-driver-found-for-jdbcmysql-localhost-dbname-error-w) could help – danielpr May 25 '21 at 03:17
  • Are you using tomcat? If so, you may need to put the jar for the MySQL database driver in the tomcat lib directory. – Woodchuck May 25 '21 at 03:26
  • Looks like you didn't put the MySQL JDBC driver on the class-path/module-path at run-time. – Slaw May 25 '21 at 17:38

0 Answers0