Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JDBC Cannot load Factory Class for Data Source

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:

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.

like image 775
Mark Achrin Avatar asked Jan 22 '14 14:01

Mark Achrin


4 Answers

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

like image 50
Kick Avatar answered Nov 07 '22 00:11

Kick


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

like image 23
Keerthivasan Avatar answered Nov 07 '22 00:11

Keerthivasan


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

like image 1
StephaneM Avatar answered Nov 06 '22 22:11

StephaneM


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

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

like image 1
David Avatar answered Nov 07 '22 00:11

David