Java program and mySQL connectivity issue: No suitable driver found

后端 未结 4 1423
忘掉有多难
忘掉有多难 2021-01-23 04:01

I\'ve been having a problem with mySQL database connectivity. I\'m getting an error:

No suitable driver found for jdbc:mysql://127.0.0.1/sakila.

4条回答
  •  不思量自难忘°
    2021-01-23 04:43

    Add the following

    String driver = "com.mysql.jdbc.Driver";
    Class.forName(driver).newInstance();
    

    right before the line "con = DriverManager.getConnection(url, user, password);"

    All you need to do is load the driver class before getting the connection from the drivermanager.

提交回复
热议问题