users@glassfish.java.net

Re: JDBC connection pooling problem

From: <glassfish_at_javadesktop.org>
Date: Wed, 27 Feb 2008 12:43:29 PST

While looking through the server.log, I came upon something that I've posted here before:

http://forums.java.net/jive/thread.jspa?messageID=259238&#259238

but I wasn't aware it was happening this frequently. It appears to be happening every time someone visits a page on the site. Whether or not is it affecting performance, it makes my server log look yucky. Help!


But back to the thread at hand....

Here is the stacktrace from the error. NoSpoon is a bean I use to return the html for the data on the test page that is causing the NPE after repeated requests:

[code]
com.techautogrp.NoSpoon.htmlFaqContents(NoSpoon.java:62)
org.apache.jsp.faq_005fconsumer_jsp._jspService(faq_005fconsumer_jsp.java from :410)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364)
javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
com.sun.enterprise.web.connector.grizzly.ssl.SSLReadTask.process(SSLReadTask.java:440)
com.sun.enterprise.web.connector.grizzly.ssl.SSLReadTask.doTask(SSLReadTask.java:228)
com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
[/code]

The bean code is:

[code]
public void connectDatabase() {
        try {
            oMySQL = new TAGDatabase("jdbc/nkb");
        } catch( Exception eException ) {}
    }

public String htmlFaqContents(int iType) {
        String htmlCode = "";
        
        String sQuery = "select col1, col2";
        sQuery += " from tablename";
        sQuery += " where col3=" + iType;
        
        try {
            ArrayList<ArrayList<String>> aResults = oMySQL.query(sQuery);
            for( ArrayList<String> aRecord : aResults ) {
                htmlCode += "<br>";
                htmlCode += "<li class=\"faq_answer\"><a href=\"#" + aRecord.get(0) + "\">" + aRecord.get(1) + "</a></li>";
            }
        } catch( SQLException eSQL ) {
            TAGLogger.addNoteEntry(1, "0", "Error getting contents of TFQ","NoSpoon.htmlFaqContents");
            setError(eSQL.getMessage() + "<br><br>" + sQuery);
        }
        
        return htmlCode;
    }
[/code]


The database connection code is:

[code]
public TAGDatabase(String sResourceName) throws NamingException, SQLException {
        InitialContext oContext = new InitialContext();
        DataSource oDataSource = (DataSource) oContext.lookup(sResourceName);
        oConn = oDataSource.getConnection();
    }

public ArrayList<ArrayList<String>> query(String sSelectStatement) throws SQLException {

        if (sSelectStatement.toLowerCase().startsWith("update")) {
            String sErrMsg = "Query is not a SELECT statement. Use the update() method to insert records.";
            throw new IllegalArgumentException(sErrMsg);
        } else {
            Statement oStatement = oConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            ResultSet oResults = oStatement.executeQuery(sSelectStatement);

            oResults.last();
            this.iRecordsReturned = oResults.getRow();
            oResults.beforeFirst();

            int iColumns = oResults.getMetaData().getColumnCount();
            ArrayList<ArrayList<String>> aResults = new ArrayList<ArrayList<String>>();

            while (oResults.next()) {
                ArrayList<String> aTemp = new ArrayList<String>();
                for (int iIterator = 1; iIterator <= iColumns; iIterator++) {
                    aTemp.add(oResults.getString(iIterator));
                }

                aResults.add(aTemp);
            }

            oResults.close();
            return aResults;
        }
    }

[/code]
[Message sent by forum member 'malakh' (malakh)]

http://forums.java.net/jive/thread.jspa?messageID=261265