chaitu chaitu
asked on
difference between statement and preparedstatement
what is the difference between statement and preparedstatement?
why we prefer preparedstatement over statement in JDBC?
i heard preparedstatements comes as compiled statements ?what is the meaning by that?
can u tell me in detail
why we prefer preparedstatement over statement in JDBC?
i heard preparedstatements comes as compiled statements ?what is the meaning by that?
can u tell me in detail
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
From the last I quote:
"Because PreparedStatement objects are precompiled, their execution can be faster than that of Statement objects.
Consequently, an SQL statement that is executed many times is often created as a PreparedStatement object to increase efficiency."
"Because PreparedStatement objects are precompiled, their execution can be faster than that of Statement objects.
Consequently, an SQL statement that is executed many times is often created as a PreparedStatement object to increase efficiency."
ASKER
HI
con.createStatement("selec t * from emp where eno="+eno);
con.prepareStatement("sele ct * from emp where eno=?);
WHaT Benifits Preparedstatement give over statement when i write quesries like that?
con.createStatement("selec
con.prepareStatement("sele
WHaT Benifits Preparedstatement give over statement when i write quesries like that?
> i heard preparedstatements comes as compiled statements ?what is the
> meaning by that?
PreparedStatements are precompiled into the database and this is more efficient when you have to execute a query several times.
> meaning by that?
PreparedStatements are precompiled into the database and this is more efficient when you have to execute a query several times.
PreparedStatements can also be slower.
> WHaT Benifits Preparedstatement give over statement when i write
> quesries like that?
Another benefit is that you do not have to worry about special characters in the string "eno" when you use a PreparedStatement.
> quesries like that?
Another benefit is that you do not have to worry about special characters in the string "eno" when you use a PreparedStatement.
> WHaT Benifits Preparedstatement give over statement when i write quesries like that?
none, unless you are executing the same query multiple times.
none, unless you are executing the same query multiple times.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PreparedStatement goes a long way to preventing SQL Injection attacks...
http://www.securiteam.com/securityreviews/5DP0N1P76E.html
http://www.securiteam.com/securityreviews/5DP0N1P76E.html
:)
Thanks
A "PreparedStatement" object is a Statement that also supports passing parameters to the query.