I’m trying to connect to MySQL using JDBC connection in a Servlet.I’m using Eclipse and added the mysql-connector-java-5.1.20-bin.jar in /WEB_INF/lib folder.
Also the same jar is also added into Java Build Path.After running the project I’m getting the following error
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.shubh.Download.doGet(Download.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
Although I’ve added the required jar in the classpath. Why is the ClassNotFoundException still generating ?
Here is my code.
Usually, dropping
.jarinWEB-INF/libshould work.eclipseis smart enough to recognize files added inWEB-INF/lib.Just to check you can look in
.classpathfile to see whether it contains an entry like<classpathentry kind="lib" path="WebContent/WEB-INF/lib/mysql-connector-java-5.1.20-bin.jar"/>But, It is advised not to hassle with
classpathentry. Remove all unnecessary reference from Java Build Path and then clean and build again should work.