AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PreparedStatement

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
RCS
Guest





PostPosted: Sun Dec 07, 2003 4:14 pm    Post subject: PreparedStatement Reply with quote



I was wondering if PreparedStatement has some benefits over Simple
Statement, even after the statement is closed.

In other words, will PreparedStatement in this scenario

Connection conn = /* get a connection from a connection pool */

PreparedStatement stmt = conn.prepareStatement("SELECT SOMETHING FROM
SOMETABLE WHERE OID=?");

/* set placeholder and execute query */

stmt.close();

/* release connection */


have any benefits over a simple Statement next time the query runs, even
if the PreparedStatement has been closed in the meantime?

Regards,
RCS

Back to top
Joe Weinstein
Guest





PostPosted: Sun Dec 07, 2003 5:47 pm    Post subject: Re: PreparedStatement Reply with quote




RCS wrote:

Quote:
I was wondering if PreparedStatement has some benefits over Simple
Statement, even after the statement is closed.
In other words, will PreparedStatement in this scenario

Connection conn = /* get a connection from a connection pool */

PreparedStatement stmt = conn.prepareStatement("SELECT SOMETHING FROM
SOMETABLE WHERE OID=?");

/* set placeholder and execute query */

stmt.close();

/* release connection */

have any benefits over a simple Statement next time the query runs, even
if the PreparedStatement has been closed in the meantime?
Regards,
RCS

It certainly can benefit. The DBMS may keep the query plan for
any prepared statement available for the life of the session
(ie: until the connection is closed). Also, for fancier connection
pooling implementations (like Weblogic's) the JDBC Connection can
pool prepared/callable statements, so even if your code closes a
statement, when/if you ever ask that connection for a prepared statement
with the same SQL, you will get that pre-cached statement to re-use.

Joe Weinstein at BEA


Back to top
RCS
Guest





PostPosted: Mon Dec 08, 2003 11:39 am    Post subject: Re: PreparedStatement Reply with quote




"Joe Weinstein" <joeNOSPAM (AT) bea (DOT) com> skrev i melding
news:3FD3679D.2090900 (AT) bea (DOT) com...
Quote:
It certainly can benefit. The DBMS may keep the query plan for
any prepared statement available for the life of the session
(ie: until the connection is closed). Also, for fancier connection
pooling implementations (like Weblogic's) the JDBC Connection can
pool prepared/callable statements, so even if your code closes a
statement, when/if you ever ask that connection for a prepared statement
with the same SQL, you will get that pre-cached statement to re-use.

Thanks!

This is what I was hoping for.

RCS



Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.