Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why PreparedStatement is so called precompiled?

 
Anil Sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Rajesh Agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thanks a lot friends
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic