• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Prepared Statement and Statement

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried searching for the below questions in the Ranch but couldn't find what I want. Excuse me if the below questions where already answered and please point me to the thread if so..

1. Difference between a PreparedStatement and Statement
2. When I should go for a PreparedStatement and when for Statement?
3. Which is better of the two in performance?
4. I heard that PreparedStatement and Statement take different no. of interations when used in a loop - Is that correct?

Thanks in advance,
Jerry.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


1. Difference between a PreparedStatement and Statement


This is best answered by looking at the JavaDocs


2. When I should go for a PreparedStatement and when for Statement?


There is not absolute rule, but a general rule of thumb could be to use PreparedStatments for the vast majority of operations with the possible exception of running adhoc queries that change frequently. PreparedStatements hide a lot of the issues surrounding formatting and escaping characters in SQL queries etc. They are also compiled and added to a cache, so should perform better over time.


3. Which is better of the two in performance?


See above. Of course query performance is a much bigger topic than a simple choice of whether to use Statements or PreparedStatements.



4. I heard that PreparedStatement and Statement take different no. of interations when used in a loop - Is that correct?


Where did you hear that? What makes you think this would be the case?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic