No suitable driver found for jdbc mysql?

后端 未结 6 1342
抹茶落季
抹茶落季 2020-12-03 23:28

I am trying to write a program to connect to a MySQL database in eclipse, but I get the error \"java.sql.SQLException: No suitable driver found\".

The java

相关标签:
6条回答
  • 2020-12-03 23:36

    Load Driver class just before getting the connection.

    Use this code:

    Class.forName("com.mysql.jdbc.Driver");
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_db", "user", "passw");
    
    0 讨论(0)
  • 2020-12-03 23:38

    I had the same problem. I solved it by adding:

    Class.forName("com.mysql.jdbc.Driver");
    
    0 讨论(0)
  • 2020-12-03 23:40

    Alternatively you can also add the installed jar file to your eclipse project by selecting the project in eclipse, right click it and go down to properties, select the Java Build Path>>select the Libraries Tab>>Add external jar file and browse for the installed mysql-connector-java.jar file or any mysql java connector file int the /usr/share/java/ directory for most ubuntu users. Click okay and rebuild your project. Good luck

    0 讨论(0)
  • 2020-12-03 23:43

    you can place the path like java -cppwd/mysql-connector-java-5.1.22-bin.jar:. <classname>.

    make sure that your in same directory where the mysql driver is .

    Hope that helps .

    0 讨论(0)
  • 2020-12-03 23:55

    I encountered the same problem as you, but I handled it as follows: I copied the jar, which is called mysql-connector-java-5.1.23-bin.jar, into the \Apache Software Foundation\Tomcat 6.0\lib, and restarted tomcat. Hope that helps

    0 讨论(0)
  • 2020-12-03 23:57

    For all but the most trivial applications the CLASSPATH environment variable is NOT used. Normally the libraries are include in the Class-Path entry in the manifest of the jar, or in the -cp option of the java commandline.

    In this case you need to add the MySQL JDBC driver to the buildpath of your Eclipse project.

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