I would like to comment the article on one point, its really important to
use Try{}Finally{} blocks to ensure that the connection will return to the
pool.
In the example, if the sql throws an exception, the connection ll never
return to the pool.
However in this code, the connection ll return to the pool:
<%
Context ctx = (Context) new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/TestDS");
Connection conn = ds.getConnection();
try
{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT name FROM staff");
while ( rs.next() )
out.println( rs.getString("name") + "<br>" );
}
finally
{
conn.close();
}
%>