Roam
Roam

Reputation: 4949

Can't find com.mysql.jdbc.Driver

I have the following dependency in pom.xml of my project:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.40</version>
</dependency>

i don't have anything else related to mySQL defined in pom.xml.

however, i'm getting the following error to it:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.myPRJ.ec.utils.DatabaseUtil.getConnection(DatabaseUtil.java:50)
at com.myPRJ.ec.Login.verify.EmailVerifier.verify(EmailVerifier.java:75)
at com.myPRJ.ec.Login.verify.EmailVerifier.getVerify(EmailVerifier.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:722)

i went by the mysql-connector-java that was under C:\Program Files (x86)\MySQL\Connector.J 5.1\mysql-connector-java-5.1.40-bin.jar on my disk. i have mySQL 5.7.0 and JDBC 4.0.0 running on Eclipse. MySQL is running all fine directly on Eclipse/Database Development.

What am i doing wrong??

//=====================

EDIT:

Maven isn't updating the repository on the above dependency tag. the MySQL connectors that appeared in .m2\repository were 2-- version 5.1.30 and version 5.1.38 I manually removed them from there-- left .m2\repository\mysql empty. then ran Update Maven on Eclipse. .m2\repository\mysql still empty after this update. which MySQL connector should I go for, wat to do?

//===============

EDIT-2:

turns out i put mysql dependency under dependency-management tag, not the dependency one. after i fixed that, spent time on corrupt jar-- maven kept giving odd errors. had been working 6+ hrs straight, sorry for the false alarm! thx for insightful answers/comments.

all fixed now.

Upvotes: 1

Views: 3844

Answers (3)

Zoltan Szabo
Zoltan Szabo

Reputation: 51

I had this problem when my mysql-connector's version didn't match to the installed mysql-server. You can check the mysql-version by typing the mysql --version command in the terminal. You have to choose the corresponding version by the mysql-server distribution number e.g. don't use the mysql-connect-java:6.0.6 in case if the mysql version is: Ver 14.14 Distrib 5.7.17.

Upvotes: 0

Vasu
Vasu

Reputation: 22442

Tomcat server could not load the com.mysql.jdbc.Driver class, so you need to add the mysql-connector-java-5.1.40.jar file to the Tomcat server's application lib folder (C:\TOMCAT_HOME\apache-tomcat\webapps\YOUR_PROJECT\WEB-INF\lib) and then Restart the Tomcat Server.

Upvotes: 2

Bruno
Bruno

Reputation: 3089

You should check if your .m2 libraries are in the Deployment Assembly. Rigth click on the folder project>Deployment Assembly, and check if there is something like m2/maven libraries. If they isnt, Press "Add.."> Java Build Path Entries and add it to deploy in path WEB-INF/lib. Restart the server and that should work!

Edit--> In my eclipse the name is Maven Dependencies and the Deploy Path is WEB-INF/lib

Upvotes: 1

Related Questions