• 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

Why PreparedStatement is so called precompiled?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Can anybody explain me

'Why PreparedStatement is so called precompiled?'


Is it compiled already in Database Driver or somewhere else?
Why

"Statement is not so called precompiled?"



what is the main difference between them?

please clear my doubts.

Thanks in Advance
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With a PreparedStatement, the database driver has a chance to look at the statement and optimize it just once, and then you can reuse that work multiple times. That's because with a PreparedStatement, the SQL is specified in the constructor. With a regular Statement, the SQL you pass to the executeQuery() method is only executed once, so the driver has to redo that optimization every time you do a query. This means PreparedStatements can be a lot more efficient.
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anil,

With every query that reaches the database engine, it actually creates an execution plan based on which the records are fetched. In a PreparedStatement, all this work is done before hand and the plans need not be recreated, so with a PS the plan is already in place and this makes the execution faster. But with Statement this is prepared everytime, and thereby the execution is a bit slower as compared to the PS.
 
Anil Sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot friends
reply
    Bookmark Topic Watch Topic
  • New Topic