Tuesday, 5 June 2012

Difference between Statement and Prepared Statement


Difference Between Statement and Prepared Statement ?

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

Statement:
when you submit a simple statement to the database, at first the DataBase Managment System  parses it and sends it back with the result, when you send the same statement again the DBMS server parses it and sends back the result, so here a lot of time is consumed/wasted because the statement is parsed again and again though it has been sent twice or thrice.

it consumes a lot of time and response time will be slow.

Prepared Statement
When you  want to execute a statement object number of times when you submit a PreparedStatement the DBMS server parses it and creates a execution plan. This e-plan can be used when you again send the same statement to the database.That is the DBMS server executes the compiled statement rather that executing it from first, hence we get an precompiled statement.

And also the advanatge of using this PreparedStatement is it is used to send dynamic sql statements, which you can pass values later rather than giving the values at the time of creation.

No comments:

Post a Comment