using GlassFish 4.0 and getting No suitable driver found for jdbc:mysql error

六月ゝ 毕业季﹏ 提交于 2019-12-23 05:11:24

问题


the following error i am getting;

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/chh-cw
root cause

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/chh-cw

the following is my project structure:

is this the correct path to put the external jars??


回答1:


It depends. Who is actually creating the connection? If your application code is directly, then the JAR belongs in WEB-INF/lib. If your container is managing the connections through a JNDI resource, then the JAR needs to be in the Glassfish classpath, not WEB-INF/lib.

In Glassfish 3.x I put the JARs in domain/lib/ext or something like that.




回答2:


yes - if you do your Connection in an may LoginServerlet... with Code like this:

this.conn = DriverManager.getConnection(getConnString());

you only have to copy the mysql..connector.jar to the WEB-Inf/lib Folder or your Domain.



来源:https://stackoverflow.com/questions/19482024/using-glassfish-4-0-and-getting-no-suitable-driver-found-for-jdbcmysql-error

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