Błąd jdbc do MySQL: Nie znaleziono odpowiedniego sterownika dla jdbc: mysql: // localhost: 3306 / test? user = 'root' i hasło = '' [duplikat]

To pytanie ma już tutaj odpowiedź:

Niesławny java.sql.SQLException: Nie znaleziono odpowiedniego sterownika 9 odpowiedzi


Mam następujący kod, aby połączyć się z bazą danych mysql:

public static void insertIntoDatabase(String code,String name,String temp,String hum,String del) {
    Connection con = null;
    ResultSet rs = null;

    String url = "jdbc:mysql://localhost:3306/test";
    String user = "root";
    String password = "";

    try {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection(url, user, password);
        rs = con.prepareStatement("CREATE TABLE IF NOT EXISTS AiportDetails(code VARCHAR(50) PRIMARY KEY, " +
                "name VARCHAR(50), temp VARCHAR(50), hum VARCHAR(50), del VARCHAR(50)) ENGINE=InnoDB;").executeQuery();
        rs = con.prepareStatement("INSERT INTO AirportDetails(code,name,temp,hum,del) VALUES("+code+","+
                name+","+temp+","+hum+","+del+");").executeQuery();
    } catch (SQLException ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (con != null) {
                con.close();
            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}

Otrzymuję następujący błąd:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver


UWAGANiektóre wspólne poprawki, które znalazłem w Internecie, to:

1. The driver is not in the /WEB-INF/lib folder.
2. The url is wrong.

Nie sądzę, żeby tak było w przypadku mojego kodu.
Dziękuję Ci.

questionAnswers(1)

yourAnswerToTheQuestion