File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes precompilation of PreparedStatements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "precompilation of PreparedStatements" Watch "precompilation of PreparedStatements" New topic

precompilation of PreparedStatements

Pushker Chaubey
Ranch Hand

Joined: Dec 06, 2006
Posts: 53
What do we mean by precompiled nature of preparedstatements? where are these statements complied and stored?

Regards,<br />Pushker<br /> <br />SCBCD 5.0 90%<br />SCWCD 5.0 89%<br />SCJP 5.0 90%
Joice Jose

Joined: Jun 29, 2005
Posts: 14
PreparedStatement is more efficient than Statement object if you are executing similar statements multiple times. When a PreparedStatement is created, the SQL statement is sent to the database for precompilation. The precompiled form of a prepared statement is cached only as long as the PreparedStatement instance is alive, so the performance benefits are only obtained when reusing the same PreparedStatement instance, setting different parameters on each invocation.
Joice Jose

Joined: Jun 29, 2005
Posts: 14
Check this
Chris Hendy
Ranch Hand

Joined: Mar 04, 2006
Posts: 98
This depends on the database.

Oracle for instance will cache parsed SQL and execution plans in its own shared memory area. They will stay there even if the session that first submitted it drops the connection, unless and until they are aged out by more recently requested statements needing the space.
[ December 12, 2006: Message edited by: Chris Hendy ]
I agree. Here's the link:
subject: precompilation of PreparedStatements
It's not a secret anymore!