Bug #11584 PooledConnections getDate() & preparedStatemet Failes to load class
Submitted: 27 Jun 2005 0:26 Modified: 14 Jul 2005 18:44
Reporter: Michael Ageeb Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:Generally Available (GA) 3.1.10 OS:Linux (Fedora Core 3 & Fedora Core 4)
Assigned to: CPU Architecture:Any

[27 Jun 2005 0:26] Michael Ageeb
Description:
I'm using tomcat web server 5.5 & myfaces technololgy by apache.
i'm trying to use connection pooling.
everything is working fine but (Dates, and prepared Statements)
when i try to create a prepared statement from any pooled connection i got an exception class prepared statement cannot be loaded and the web application stops.
and this is the same when i try to retrive date from a pooled connection.

(the probelm with dates about retriving only not saving) saving is working fine

Jun 27, 2005 3:01:26 AM org.apache.catalina.loader.WebappClassLoader loadClass
INFO: Illegal access: this web application instance has been stopped already.  Could not load com.mysql.jdbc.TimeUtil.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
Jun 27, 2005 3:01:26 AM org.apache.myfaces.el.PropertyResolverImpl getValue
SEVERE: business.web.jsfmodel.PayablePurchasesTableModel
javax.faces.el.EvaluationException: Bean: business.web.jsfmodel.PayablePurchasesTableModel, property: payablePurchases
        at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:423)
        at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:104)
        at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:555)
        at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
        at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:441)
        at javax.faces.component.UIData.getValue(UIData.java:1173)
        at org.apache.myfaces.component.html.ext.HtmlDataTable.getSerializableDataModel(HtmlDataTable.java:631)
        at org.apache.myfaces.component.html.ext.HtmlDataTable.saveState(HtmlDataTable.java:574)
        at javax.faces.component.UIComponentBase.processSaveState(UIComponentBase.java:470)
        at org.apache.myfaces.component.html.ext.HtmlDataTable.processSaveState(HtmlDataTable.java:318)
        at javax.faces.component.UIComponentBase.processSaveState(UIComponentBase.java:466)
        at javax.faces.component.UIComponentBase.processSaveState(UIComponentBase.java:466)
        at javax.faces.component.UIComponentBase.processSaveState(UIComponentBase.java:466)
        at javax.faces.component.UIComponentBase.processSaveState(UIComponentBase.java:466)
        at javax.faces.component.UIComponentBase.processSaveState(UIComponentBase.java:466)
        at javax.faces.component.UIComponentBase.processSaveState(UIComponentBase.java:466)
        at javax.faces.component.UIComponentBase.processSaveState(UIComponentBase.java:466)
        at javax.faces.component.UIComponentBase.processSaveState(UIComponentBase.java:454)
        at javax.faces.component.UIComponentBase.processSaveState(UIComponentBase.java:466)
        at org.apache.myfaces.application.jsp.JspStateManagerImpl.getComponentStateToSave(JspStateManagerImpl.java:106)
        at org.apache.myfaces.application.jsp.JspStateManagerImpl.saveSerializedView(JspStateManagerImpl.java:249)
        at org.apache.myfaces.taglib.core.ViewTag.doEndTag(ViewTag.java:141)
        at org.apache.jsp.view.purchases_jsp._jspx_meth_f_view_0(purchases_jsp.java:138)
        at org.apache.jsp.view.purchases_jsp._jspService(purchases_jsp.java:89)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:673)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:464)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:399)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
        at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:405)
        at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:280)
        at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:300)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:110)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at business.web.filters.Authentication.doFilter(Authentication.java:56)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:112)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)

How to repeat:
First:-
Put this code in any web context listener
MysqlConnectionPoolDataSource cpds = new
                                                 MysqlConnectionPoolDataSource();
            cpds.setDatabaseName("dbname");
            cpds.setServerName("localhost");
            cpds.setUser("michael");
            cpds.setPassword("ageeb");
            cpds.setPortNumber(#);
            Context cxt = new InitialContext();      
            cxt.bind("dbconnection", cpds);       

Second:-
This code gets a pooled connection

public Connection getConnection(String jndi){
Context ctx = null;
          try {
              ctx = new InitialContext();
          } catch (NamingException ex) {
              ex.printStackTrace();
          }
          ConnectionPoolDataSource ds = null;
          try {
              ds = (ConnectionPoolDataSource) ctx.lookup(
                      jndi);
          } catch (NamingException ex2) {
              ex2.printStackTrace();
          }
          Connection con = null;
          try {
              con = ds.getPooledConnection().
                    getConnection();
          } catch (SQLException ex1) {
              ex1.printStackTrace();
          }
          return con;
}

Third:-
 try to execute this code from any java bean runing on a Tomcat Server
con=ConnectionManager.getConnection();
            stmt = con.createStatement();
            
            tables = new ArrayList();
            
            tables.add(Names.Tables.PORTION_TABLE);
            
            rs = stmt.executeQuery(SQLGenerator.selectStatement(null,
                    tables,
                    Names.Columns.PAYMENTDATAID_COlUMN + "=" + paymentData.getPaymentDataId())); //here any query that contain a date table
            
            ArrayList portions = new ArrayList();
            
            while (rs.next()) {
                Portion p = new Portion();
                
                p.setId(rs.getInt(1));
                rs.getInt(2);
                System.out.println("************************************************************ A new Date is required.");
                java.sql.Date o = rs.getDate(3);
                System.out.println("************************************************************" + o.getClass());
                //p.setDate(d);
                p.setAmount(rs.getDouble(4));
                p.setPaid(rs.getBoolean(5));
                
       
to repeat the bug of preparedStatemet Just try 
con.prepareStatement()

Suggested fix:
detDate() should return a java.sql.date without any exceptions.
con.prepareStatement() should load the class and return a PreparedStatemet object instead of exceptions
[27 Jun 2005 12:39] Mark Matthews
Sounds like a classloader/configuration issue to me. Where are you placing the class files for the JDBC driver?

(trust me, plenty of users use Apache and Tomcat with DBCP _and_ use prepared statements and dates with no errors or exceptions).

Did you editorialize the stack trace in any way? I don't see anything in it that would say why it couldn't load com.mysql.jdbc.TimeUtil which is a pretty plain-vanilla class.

Are you binding MysqlConnectionPoolDataSource directly into JNDI and expecting it to be a connection pool? (It isn't one). The ConnectionPoolDataSource API is there to specify a DataSource that can provide connections _for_ a pooling implementation, not implement a pool itself. If this is the case for your application, I suggest using an actual connection pool, such as C3P0 or DBCP.
[14 Jul 2005 18:44] Michael Ageeb
ok it's not a bug i think it was a mistake of mine