Answer the question
In order to leave comments, you need to log in
What causes the error java.sql.SQLException: No suitable driver found for jdbs:mysql://localhost:3306/mydbtest?
Full text of console output:
[email protected]
Driver successfully registered
Connection not established
java.sql.SQLException: No suitable driver found for jdbs:mysql://localhost:3306/mydbtest
at java.sql/ java.sql.DriverManager.getConnection(DriverManager.java:702)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
at database.Main.main(Main.java:33)
package database;
import com.mysql.cj.jdbc.Driver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main {
private static final String URL = "jdbs:mysql://localhost:3306/mydbtest";
private static final String USERNAME = "root";
private static final String PASSWORD = "12345trip";
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Connection connection = null;
try {
Driver driver = new com.mysql.cj.jdbc.Driver();
DriverManager.registerDriver(driver);
Class.forName("com.mysql.cj.jdbc.Driver"); //нужен ли он ??
System.out.println(driver.toString());
System.out.println("Драйвер успешно зарегистрирован");
} catch (SQLException e) {
e.printStackTrace();
System.err.println("Не удалось загрузить класс драйвера");
}
try {
connection = DriverManager.getConnection(URL,
USERNAME, PASSWORD);
System.out.println(connection);
if(! connection.isClosed()){
System.out.println("Соединение установлено");
}
}catch (SQLException e){
System.err.println("Соединение не установлено");
e.printStackTrace();
}
finally {
if (connection != null) {
connection.close();
System.out.println("Соединение закрыто");
}
}
}
}
Answer the question
In order to leave comments, you need to log in
"jdb s :mysql://localhost:3306/mydbtest"
should definitely be changed to
"jdb c :mysql://localhost:3306/mydbtest"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question