-1

I'm trying to write a Java program connecting to a MySQL database. But I'm getting this error:

java.sql.SQLException: No suitable driver found for jbdc:mysql://loclalhost:3306/passwortmanager
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
    at passwordManager.dataHandler.ConnectDB.createConnection(ConnectDB.java:24)
    at passwordManager.dataHandler.ConnectDB.main(ConnectDB.java:36)

And here is my code:

public class ConnectDB {
    //DB Connection variables

    static Connection connection = null;
    static String databasename = "passwortmanager";
    static String url = "jbdc:mysql://localhost:3306/" +databasename;

    static String username = "root";
    static String password = "password";


    void createConnection(){
        System.out.printf(url);
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection = DriverManager.getConnection(url,username,password);

            System.out.println("Connectet to Database");
        }catch (ClassNotFoundException ex){
           Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE,null,ex);
        }catch (SQLException ex){
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE,null,ex);
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new ConnectDB().createConnection();
    }
}

I already tried added the maven library to the project: pciture of the library Here you can see the project structure with the added librarys

What am I doing wrong?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Does this answer your question? [The infamous java.sql.SQLException: No suitable driver found](https://stackoverflow.com/questions/1911253/the-infamous-java-sql-sqlexception-no-suitable-driver-found) – nbk Nov 07 '20 at 12:18
  • @nbk Thx fore the response but it dont work I already added the mysql-connector-java-8.0.22.jar to the project – Gollum8123 Nov 07 '20 at 12:29
  • How are you running your application? Please tell us the exact command line that you are using. – Stephen C Nov 07 '20 at 12:32
  • 1
    @Gollum8123 you must read the complete answer,there you will see that installing is not enough.or else you wouldn't have a problem – nbk Nov 07 '20 at 12:36
  • @nbk I cant find this folder /WEB-INF/lib – Gollum8123 Nov 07 '20 at 12:47
  • You have a typo in your JDBC URL. You use `jbdc:mysql:...`, a correct URL starts with `jdbc:mysql:...` – Mark Rotteveel Nov 08 '20 at 08:05

1 Answers1

0

There looks to be a typo in your url, swap jbdc -> jdbc here:

static String url = "jdbc:mysql://localhost:3306/" +databasename;
DuncG
  • 12,137
  • 2
  • 21
  • 33