Java JDBC 无法加载数据源的工厂类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21286174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 07:54:34  来源:igfitidea点击:

JDBC Cannot load Factory Class for Data Source

javamysqltomcatjdbc

提问by Mark Achrin

I have been having this problem for days and have not managed to fix it. I am using tomcat 7.0 and I am completely unable to get a mysql database connection going. The application I am writing is a jsp dynamic website using the eclipse IDE. I get this error when TomCat 7 starts up:

我已经有这个问题好几天了,一直没能解决。我正在使用 tomcat 7.0,但我完全无法建立 mysql 数据库连接。我正在编写的应用程序是一个使用eclipse IDE 的jsp 动态网站。TomCat 7 启动时出现此错误:

WARNING: Failed to register in JMX: javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool.DataSourceFactory]

I also get this error:

我也收到此错误:

javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool.DataSourceFactory]
    at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:84)
    at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:826)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:145)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:814)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:145)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:814)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:145)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:814)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at test.General.Database.getConnection(Database.java:21)
    at test.Controller.LoginServlet.doPost(LoginServlet.java:43)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool.DataSourceFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:82)
    ... 31 more

when I get to this code:

当我看到这段代码时:

  try {
        Context ctx = new InitialContext();
        ds = (DataSource)ctx.lookup("java:comp/env/jdbc/chitchat");
      } catch (NamingException e) {
        e.printStackTrace();
      }

Anyone have any ideas what my problem is? I've had this for quite literally days now and I really want to move on from this.

任何人都知道我的问题是什么?我已经有好几天了,我真的很想继续前进。

采纳答案by Kick

org.apache.tomcat.jdbc.pool.DataSourceFactory jar not exist in ur classpath

你的类路径中不存在 org.apache.tomcat.jdbc.pool.DataSourceFactory jar

回答by Keerthivasan

You have to place tomcat-jdbc.jarin your tomcat lib folder. it can be downloaded from this link

你必须放在tomcat-jdbc.jar你的 tomcat lib 文件夹中。它可以从这个链接下载

回答by StephaneM

In what jar is the class org.apache.tomcat.jdbc.pool.DataSourceFactory? Is this jar in your classpath?

org.apache.tomcat.jdbc.pool.DataSourceFactory 类在哪个 jar 中?这个 jar 在你的类路径中吗?

回答by David

I just encountered this when using an Eclipse-downloaded Tomcat. It was missing that tomcat-jdbc.jarthat others mentioned.

我刚刚在使用 Eclipse 下载的 Tomcat 时遇到了这个问题。缺少tomcat-jdbc.jar其他人提到的。

I solved it by downloading a Tomcat zip from the Tomcat website and pointing Eclipse to that instead.

我通过从 Tomcat 网站下载 Tomcat zip 并将 Eclipse 指向它来解决它。