• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

 
Raminder Skhurana
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP Status 500 - javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

type Exception report

message javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

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

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:565)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)
org.apache.jsp.rami_jsp._jspService(rami_jsp.java:163)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
ramihtml.Userdao.rami(Userdao.java:11)
org.apache.jsp.rami_jsp._jspService(rami_jsp.java:144)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)



I have added the MYSQL  connector file but still it's giving me this error.
What should i do?


 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You added the mysql jdbc jar to your project so your code compiles. But when run on server didn't work?

Make sure your exported war file has the mysql jar in it.

If you are using a app server, the proper way is to set up a database connection pool and use JNDI to get the resource (hence no jdbc code). However, if your project is small or for testing setting up such a pool is not worth while.
 
Raminder Skhurana
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:You added the mysql jdbc jar to your project so your code compiles. But when run on server didn't work?

Make sure your exported war file has the mysql jar in it.

If you are using a app server, the proper way is to set up a database connection pool and use JNDI to get the resource (hence no jdbc code). However, if your project is small or for testing setting up such a pool is not worth while.


Mysql connector is there..Works fine on JavaApplication as well but not on server!
 
Knute Snortum
Sheriff
Posts: 3332
84
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you using to build the war file?  Maven?  Ant?  Gradle?
 
Dave Tolls
Ranch Hand
Posts: 2389
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:You added the mysql jdbc jar to your project so your code compiles.


The nature of JDBC code is such that you don't need the driver jar file on the classpath when compiling.

But this does look like a simple case of the connector not ending up on the server in the lib folder.
However, I'm a firm believer that any web app should use a connection pool.  Not doing so will end up biting you, IMO.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!