当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - SQLException: No suitable driver found

问题描述:

This question already has an answer here:

  • The infamous java.sql.SQLException: No suitable driver found

    3 answers

网友答案:

java.sql.SQLException: No suitable driver found

This exception can have 2 causes:

  1. The JDBC driver is not loaded at all.
  2. URL does not match any of the loaded JDBC drivers.

Since the driver seems to be loaded (although in an incorrect manner), it look like that the URL is plain wrong. Ensure that the value of your url variable matches the following format

jdbc:mysql://localhost:3306/dbname

See also:

  • Java connectivity with MySQL

Unrelated to the concrete problem: Java code doesn't belong in a JSP file. Work on that as well. Your exception handling is also terrible, you should throw the exception (so that it blocks executing the remnant of the code) instead of printing the message/trace and then continue with the code.

网友答案:

Did you register your class with the Driver? For example:

Class.forName("net.sourceforge.jtds.jdbc.Driver");
DriverManager.getConnection(url,user,password);
网友答案:

I had to remove mysql-connector-java-*.jar from WEB-INF/lib and add it into tomcat6/lib folder. (tomcat6 is where tomcat was installed.) I do not know why this worked but it worked for me.

网友答案:

Are you passing an emtpy url string to getConnection()? The error message starts out

No suitable driver found for ERROR

No suitable driver found for [blank]? Seems like you're not passing a url here.

网友答案:

Go to library folder of your project and right click it,then go to 'Add Library' option.Now add the mysql.jdbc.Driver

分享给朋友:
您可能感兴趣的文章:
随机阅读: