T
T
The_XXI2021-02-21 20:40:05
Java
The_XXI, 2021-02-21 20:40:05

Why can't I connect to the local database?

Started local mysql server.
I'm trying to connect to it:

public class UserEntityManager {

    public static void add(UserEntity user) throws SQLException {

        Connection connection = DriverManager.getConnection("jdbc:mysql//localhost/javadb", "root", "");

        String sql = "INSERT INTO users(login, password, age, job) VALUES(?, ?, ?, ?)";

        //Statement s = connection.createStatement();
        //s.executeUpdate(sql);

        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setString(1, user.getLogin());
        ps.setString(2, user.getPassword());
        ps.setInt(3, user.getAge());
        ps.setString(4, user.getJob());

        ps.executeUpdate();
    }
}

Gives an error message:
java.sql.SQLException: No suitable driver found for jdbc:mysql//localhost/javadb
  at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
  at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
  at org.company.app.database.manager.UserEntityManager.add(UserEntityManager.java:11)
  at org.company.app.Main.main(Main.java:15)

What's the matter?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-02-21
@The_XXI

The fact that there is no jdbc driver for MySQL in the classpath.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question