0

I am using eclipse for creating servlets. I downloaded the mysql-connector-java-5.0.8-bin.jar (connector/j) and added the jar file to build path of my project. I can use the classes in mysql-connector-java-5.0.8-bin.jar (IDE gives me hints and all that stuff and there is no problem using those classes in compile time) . but when i run the servlet i get this error:

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

It sounds like suddenly the com.mysql.jdbc.Driver class that i've been using can not be found!

When i use the jar file for java SE projects it works perfect but it doesn't work with javaEE. How can i fix this?

Gandalf
  • 2,921
  • 5
  • 31
  • 44

2 Answers2

1

The database connector jar should be set as the runtime classpath instead of the build paths since database driver is a runtime dependency.

evanwong
  • 5,054
  • 3
  • 31
  • 44
0
  • Drop the jar into the WEB-INF/lib folder.
  • WEB-INF/lib folder is for application specific jars.
  • You could also use your servlet container's common/lib folder for jars which are common to several web applications.
Teddy
  • 4,009
  • 2
  • 33
  • 55