My understanding is that the benefit of a PreparedStatement is that you
"prepare it" ONCE and then "execute it" over and over. Thus, the server has
a chance to optimize complicated SQL statements ahead of time. So, based on
this reasoning, one might choose to "prepare" all of your statements in the
servlet's init() method. Then execute them in the servlet's service (or
doGet) method over and over.
My Question is, how does one receive this "prepare" benefit when using J2EE
style connection pooling? Here is my code:
try{
String SQL = ....
Context nCtx = new InitialContext();
DataSource ds = (DataSource)nCtx.lookup("jdbc/pooled/mysql_ss1");
conn = ds.getConnection();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
/* use the ps here */
}
finally{
if(ps!=null) ps.close();
if(conn!=null) conn.close();//this really "releases" rather than "closes"
the connection
}
Since the scope of conn is local to the service method, and ps is connected
to conn, how can a ps ever live longer than the service method?
Thanks,
Dave Ford
P.S. Is it politically correct, to post to more than one newsgroup?
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html