File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Statement vs PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Statement vs PreparedStatement" Watch "Statement vs PreparedStatement" New topic
Author

Statement vs PreparedStatement

PNS Subramanian
Ranch Hand

Joined: Jul 13, 2004
Posts: 150
PreparedStatement, it is said offers better performance that Statement object by virtue of being "pre-compiled". When the above pre-compilation takes place, the SQL query is fine-tuned for various aspects, one among which is performance - this ofcourse, is based on the current size/contents of the table. What if the table size is so large, and the PreparedStatement is used for a large number of operations - wont the query optimization be wrong in that case ?Rather, wont this wrong optimization affect the performance in the long run ?
PNS Subramanian
Ranch Hand

Joined: Jul 13, 2004
Posts: 150
Awaiting a response for this.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
An execution plan can become less appropriate as the volume or composition of the data changes, but it's up to the database and/or its JDBC driver to decide how long to cache a plan for. You would hope that there is some invalidation mechanism, even if it is only a maximum age.

- Peter
satish sathineni
Ranch Hand

Joined: May 03, 2004
Posts: 46
Prepared Statements by virtue are reusable statements rather
creating a new statement every time . as the normal Statement does...

As u said Prepared Statements does not do or write any performance tuning internally....

For performance reasons mean for using the same statement repeatedly we use Prepared Statement for example insert statement ...

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Statement vs PreparedStatement
 
Similar Threads
When does a PreparedStatement produce better performance than a Statement?
join and in
pre-compile and prepared statement
Prepared statment
Difference between Statement/Prepared statement?