5 Replies Latest reply on Feb 3, 2002 12:50 PM by Craig Johannsen

    How to exploit prepared statements

    Craig Johannsen Newbie

      The idea of prepared statements is to be able to use the same prepared statement over and over again many times. However, the convention in bean-managed entity beans is to get a connection (presumeably from the connection pool), use it, and then close it in each method, which means the prepared statements, if any, are used only once, I think.

      Would it be reasonable in setEntityContext to get the connection, prepare a set of frequently used SQL statements (containing "?" parameters), and then in the other methods call getConnection, use the connection, but not close it. Would this allow the prepared statements to remain open? If so, it would be a lot more efficient than dynamically constructing the SQL every time.

      Would unsetEntityContext be the correct place to close the connection in the above case?