Java program and mySQL connectivity issue: No suitable driver found

后端 未结 4 1424
忘掉有多难
忘掉有多难 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:34

    You need to instantiate the driver before calling the getConnection :

    String pdriver = "com.mysql.jdbc.Driver";
    Class.forName(pdriver).newInstance();
    
    0 讨论(0)
  • 2021-01-23 04:34

    You need to add the MySQL connecter library jar file to the classpath, rather than the directory where it is contained.

    Are you not using an IDE like Netbeans or Eclipse? Setting up a command line development environment in Windows is not hard but it's not trivial either

    0 讨论(0)
  • 2021-01-23 04:38

    You need to place the connector jar file to your classpath or ...\jre1.6.0\lib\ext

    Classpath is the one you should favor instead of the latter
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题