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.
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.
posted 10 years ago
thanks a lot friends
Anil Sharma<br />SCJP 1.4, SCWCD 1.4(Preparing)
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads