Saturday, February 3, 2007

why do we use prepared statement when statement is there

a. Prepared statement is a precompiled statement, it is mailnly used for the speed up the prcoss of inserting/updating/deleting when there is a bulk processing.

b. Actually when u submit a simple statement to the database, at first the DBMS parses it and sends it back with the result, so again when u send the same statement again the DBMS server parses it and sends back the result so here a lot of time is wasted and because the statement is again parsed though it has been sent twice or thrice it consumes a lot of time and response will be slow. Prepared Statement is used when u want to execute a statement object many times. When u submits a PreparedStatement the DBMS server parses it and creates an execution plan. This e-plan can be used when u again send the same statement to the database. That is the DBMS server zest executes the compiled statement rather that executing it from first, hence we get a precompiled statement. And also the advantage of using this PreparedStatement is it is used to send dynamic sql statements, which u can give values later than giving the values at the time of creation.

c. Prepared Statement is Pre-compiled class, but Statement is not.So in PreparedStatement the execution will be faster.

SOURCE : www.referjava.com

No comments: