answersLogoWhite

0


Best Answer

* Prepared Statement is Pre-compiled class , but Statement is not. * So in PreparedStatement the execution will be faster. Actually when u submit a simple statement to the databse, 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 submit a PreparedStatement the DBMS server parses it and creates a 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 an precompiled statement.And also the advanatge 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.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

The PreparedStatement is a slightly more powerful version of a Statement and should always be at least as quick and easy to handle as a Statement.
The PreparedStatement may be parametrizednull

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.

Another advantage of the PreparedStatement class is the ability to create an incomplete query and supply parameter values at execution time. This type of query is well suited for filtering queries which may differ in parameter value only:


SELECT firstName FROM employees WHERE salary > 50
SELECT firstName FROM employees WHERE salary > 200

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between Statement and PreparedStatement?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What kind of statement is precompiled and stored in a PreparedStatement object?

A programming statement is precompiled and stored in a PreparedStatement object. It is usually a statement that is repeated and executed many times throughout the program.


What is difference between basic command and statement?

difference between command and statement


What is the difference between bar scale and statement scale?

What is the difference between a bar scale and a statement scale


What are the difference between command and statement?

i am starving


What is the difference gwbasic commands and statements?

difference between command and statement


Difference between scope statement and project charter?

The difference between a scope statement and a project charter is that a project charter acknowledges the projects existence and the scope statement defines the project objectives.


What is the difference between 'switch' statement and 'if' statement?

we can use switch statement in multiple time but in if statement we can not use multiple time


What is the difference between a declarative statement and an imperative statement?

In a declarative statement, you initialize the object. But in an imperative statement, you use a preexisting statement and use it.


What is the difference between a fact and a statement?

The difference between fact and statement is that a fact is something that is empirically true and can be supported by evidence while a statement is a belief that may or may not be backed up with some type of evidence.


What is difference between control statements and looping statements in c language?

differance between control statement and looping statement?


What is the difference between policy and policy statement?

Policy statement is what you say you are going to do. Policy is what you do, which should be in line with the policy statement.


What is the difference between a problem statement and a mission statement?

Perhaps the difference lies in the distinct meaning or the words in question. For the problem statement, state the problem. For the mission statement, state your mission, or how you will address the problem.