Hi Nidhi!!
Most relational databases handles a
JDBC / SQL query in four steps:
1)Parse the incoming SQL query
2)Compile the SQL query
3)Plan/optimize the data acquisition path
4)Execute the optimized query / acquire and return data
A
Statement will always proceed through the four steps above for each SQL query sent to the database. A
PreparedStatement pre-executes steps (1) - (3) in the execution process above. Thus, when creating a PreparedStatement some pre-optimization is performed immediately. The effect is to lessen the load on the database engine at execution time.
Using prepare statement is less expensive 'coz, it pre executes the follwoing steps. Step 1 :Parse the incoming SQL query Step 2 :Compile the SQL query Step 3 :Plan/optimize the data acquisition path Where will be the pre executed steps stored, i.e) in Application server or in DataBaseServer
For more information go through this
thread Diff Between Statement and PreparedStatement I hope it helps you to some extent.
SCJP(1.5),SCWCD(On the way....)
Dhwani:>Winning is not important but it is the only thing.