Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
anwar pasha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing simple servlet and jdbc code to insert the data into database
when trying to insert the data i am getting below error ,
i have given mysql-connector.jar file in classpath still its comming the error
can help me please..........


java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1352)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at DbCon.getConnection(DbCon.java:12)
at HelloAleemExample.doGet(HelloAleemExample.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at

.
..
.
.
.
 
Jan Cumps
Bartender
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the documentation of your application server (is it Tomcat?). There will be a topic on how to add jar files to the classpath of that application server.
Typically, you have to place the jar file in a specific directory.
 
Mick Foley
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using Tomcat Web container, add your jar file under the WEB-INF/lib directory for your web application. Hope that works for you.
 
uday kantt
Greenhorn
Posts: 26
Java MyEclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
So it is looking for a class called Driver in the com.mysql.jdbc package. For this you need to add the mysql-connector-java-5.0.8-bin.jar file to the classpath. Then things work fine.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic