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
LVL 20
chaitu chaituAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zzynxSoftware engineerCommented:
In JDBC, you can pass an SQL query or command in a "Statement" object.
A "PreparedStatement" object is a Statement that also supports passing parameters to the query.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

zzynxSoftware engineerCommented:
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."
0
chaitu chaituAuthor Commented:
HI

con.createStatement("select * from emp where eno="+eno);
con.prepareStatement("select * from emp where eno=?);


WHaT Benifits Preparedstatement give over statement when i write  quesries like that?
0
girionisCommented:
> 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.
0
objectsCommented:
PreparedStatements can also be slower.
0
girionisCommented:
> 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.
0
objectsCommented:
> WHaT Benifits Preparedstatement give over statement when i write  quesries like that?

none, unless you are executing the same query multiple times.
0
girionisCommented:
Here is some good info and performance tips about Statement, PreparedStatement and CallableStatement: http://www.theserverside.com/articles/article.tss?l=JDBCPerformance_PartIII
0
petmagdyCommented:
0
TimYatesCommented:
PreparedStatement goes a long way to preventing SQL Injection attacks...

http://www.securiteam.com/securityreviews/5DP0N1P76E.html
0
girionisCommented:
:)
0
zzynxSoftware engineerCommented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.