Answer the question
In order to leave comments, you need to log in
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();
}
}
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)
Answer the question
In order to leave comments, you need to log in
The fact that there is no jdbc driver for MySQL in the classpath.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question