On Wed, 2 Aug 2000 17:39:14 +1000, James Webster <[EMAIL PROTECTED]>
wrote:
>A typically ejbStore() method (assuming bean-managed persistence) might
>look like this...
>
>
>public void ejbStore()
>{
> InitialContext context = new InitialContext();
> DataSource ds = (DataSource)context.get("/some/jndi/name");
> Connection conn = ds.getConnection();
> PreparedStatement stmt = conn.preparedStatement("update bleah set
>colOne = ?, colTwo = ? where colThree = ?")
>
> ...
>
> conn.close();
>}
Yup, agree.
>1. Most of the EJB books show the Connection that is obtained from the
>DataSource being closed at the end of the method. Why? If the EJB server is
>responsible for maintaining a pool of database connections, then surely it
>alone should be responsible for adding and removing Connections from this
>pool.
In some cases the connection is not the actual database connection, but
rather a wrapper provided by the EJB server. In that case "close()"
doesn't really close the connection, but only puts the used connection
back into the pool.
In case of JDBC2.0 I think you indeed have the real connection to work
with, but then there is a similar framework in place which puts the
connection back into the pool. (I might be wrong on this second option;
however, most servers use the first since JDBC2.0 drivers are scarce)
>2. Is there any way to take advantage of good JDBC drivers, that work with
>the database to construct the query plan for PreparedStatements ONCE (when
>they are constructed) rather than every single time they are constructed?
Well, in the above scenario, if you are indeed using a wrapper provided
by the EJB server, the wrapper can do this optimization for you (i.e.
caching actual prepared statements with the SQL query as key to a
hashmap).
I would assume that this is the case anyway.
/Rickard
--
Rickard �berg
Email: [EMAIL PROTECTED]
http://www.telkel.com
http://www.jboss.org
http://www.dreambean.com
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".