[prev in list] [next in list] [prev in thread] [next in thread] 

List:       struts-dev
Subject:    Re: PreparedStatements pool.
From:       "George Lessmann" <glessmann () ponvia ! com>
Date:       2001-01-31 19:59:09
[Download RAW message or body]

From: "Johan Compagner" <jcompagner@j-com.nl>
> I was just wondering if i gane much when i also pool all my
> PreparedStatements.

Pooling PreparedStatements probably isn't going to gain you all that much.
PreparedStatements are already kept by the database, so they're likely to be
as efficient as possible without optimizing your queries, since more time is
spent in the database than in instantiating a PreparedStatement. What I do
is something like this:

public interface PreparedStatementInterface
{
public PreparedStatement setFields(PreparedStatement pstmt) throws
SQLException;
public String getSQL();
}

and then,

public final class DateStatement implements PreparedStatementInterface
{
    private static final String select = "SELECT sysdate FROM dual";

public PreparedStatement setFields(PreparedStatement preparedStatement)
throws SQLException
 {
    //do things
    //preparedStatement.setInt(1);
  return preparedStatement;
 }// setFields

 public String getSQL()
 {
    // could also manipulate the statement for more dynamic queries...
    return select;
 }// getSQL

}// DateStatement

I use this strucutre to encapsulate all of the things a PreparedStatement
does, and came up with it after I inherited some code that was using
StringBuffers for building dynamic sql...

As a side note, don't the notes on the future directions of the HotSpotVM
specifically state not to pool resources since pooling defeats some of the
possible optimizations?

hth,

George Lessmann

Ponvia Technology, Inc

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic