Rudi,

I have two things to add that nobody seems to have mentioned.

In my LoginServlet, I create a new PooledConnection, which I add to the
Servlet Context:

PooledConnection pc = ConnectionFactory.getInstance.getPooledConnection();
ServletContext ctx = getServletContext();
ctx.setAttribute("pooled_conn", pc);

Gah! Why are you putting a database connection into the application context? This sounds like a concurrency nightmare! I think you want to put the /pool/ into the application scope, not a single connection.

Connection con = pc.getConnection
//do a few things with the connection

try{
    if (con != null){
        con.close();
    } // I'm assumingthis returns the connection to the Pool

}catch(SQLException sqle){
    sqle.printStackTrace();
}

You need more try/catch blocks. conn.close should /always/ be in a finally block:

Connection conn = null;
// Declare your statements and resultsets, here, too

try
{
        conn = // whatever

        // Do stuff with connection
}
finally
{
        // Close your statements and result sets, here, too

        if(null != conn)
                try { conn.close(); } catch (SQLException sqle)
                { /* log this exception somewhere */ }
}

Hope that helps,

-chris

Attachment: signature.asc
Description: OpenPGP digital signature



Reply via email to