 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
RCS Guest
|
Posted: Sun Dec 07, 2003 4:14 pm Post subject: PreparedStatement |
|
|
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
|
Posted: Sun Dec 07, 2003 5:47 pm Post subject: Re: PreparedStatement |
|
|
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
|
Posted: Mon Dec 08, 2003 11:39 am Post subject: Re: PreparedStatement |
|
|
"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 |
|
 |
|
|
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
|
|