• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Statement vs PreparedStatement

 
PNS Subramanian
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awaiting a response for this.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic