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.
Joined: Nov 07, 2005
thanks a lot friends
subject: Why PreparedStatement is so called precompiled?