Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Statement vs. Prepared Statement

 
Debalina Bera
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know the clear difference between the use of statement and prepared statement. In case of prepared statement, the object is created first time in the memory of database and can be used for all later invocation. If that is true, in all our web application, we should use prepared statement always, since multiple users will be accessing the website and the same object of that prepared statement can be used multiple times. My doubt is that, what is the purpose of having normal statement then? Another confusion, when at the end of method we close the prepared statement, does the object get closed from the memory of the database as well or only gets closed from the server?
Appreciate your detailed input on this.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, you should read this article.
Second, you don't have to worry about any "objects" being "closed" in the database. What the use of PreparedStatement does in the database is basically caching; the database engine compiles the SQL skeleton into a query plan and caches the resulting "executable". It's up to the database server whether it wants to keep the compiled stuff in memory after the statements have been executed and committed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic