Idea运行web项目时,提示java.lang.ClassNotFoundException: com.mysql.jdbc.Driver解决方法

Posted 必须往前走

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Idea运行web项目时,提示java.lang.ClassNotFoundException: com.mysql.jdbc.Driver解决方法相关的知识,希望对你有一定的参考价值。

今天用 idea写了个工程。结果最后报错,错误信息如下:


java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1493)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.google.model.ConnDB.getConn(ConnDB.java:16)
at com.google.model.GoodsBeanBO.getGoodsBean(GoodsBeanBO.java:23)
at com.google.servlet.showGoodsClServlet.doGet(showGoodsClServlet.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:722)
java.lang.NullPointerException
at com.google.model.GoodsBeanBO.getGoodsBean(GoodsBeanBO.java:25)
at com.google.servlet.showGoodsClServlet.doGet(showGoodsClServlet.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:722)

 

 

  从头到尾看了好几遍,没发现错误。郁闷的要死。调试。。。调试。。。调试。。。丫的!

  浪费了几个钟头的时间!竟然脑残的忘记 google 了! 最后 google 一下。结果出现了。  

  原来是tomcat找不到MYSQL JAR包!

  必须把mysql-connector-java-5.1.7-bin.jar导入到tomcat的lib目录下面! FUCK! 

  在java项目中,只需要引入mysql-connector-java-5.1.7-bin.jar就可以运行java项目。

  在web项目中,当Class.forName("om.mysql.jdbc.Driver");时myeclipse是不会去查找字符串,不会去查找驱动的。所以只需要把mysql-connector-java-   5.1.7-bin.jar拷贝到tomcat下lib目录就可以了。

 

  特别在此记录一下!记录自己的愚蠢!同时多谢  http://blog.csdn.net/huangbiao86/article/details/6428608 这位朋友的帖子!!








































以上是关于Idea运行web项目时,提示java.lang.ClassNotFoundException: com.mysql.jdbc.Driver解决方法的主要内容,如果未能解决你的问题,请参考以下文章

idea 创建运行web项目时,报错: Can not issue executeUpdate() for SELECTs解决方案

idea调试web项目时出现:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL解决方案

IntelliJ IDEA 上的web项目进行数据库连接时出现java.lang.ClassNotFoundException: com.mysql.jdbc.Driver错误解决办法

idea控制台运行tomcat,报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderLi

在 IDEA 终端中运行激活器命令时出现 java.lang.NoClassDefFoundError

tomcat启动报错:Internal error (java.lang.IllegalStateException): Duplicate key org.jetbrains.jps.model.m