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();
}
}
}