SQLException: No suitable driver found [duplicate]

萝らか妹 提交于 2019-11-26 19:06:54
BalusC

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:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!