[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 467
  • Last Modified:

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
0
chaitu chaitu
Asked:
chaitu chaitu
  • 4
  • 4
  • 3
  • +3
3 Solutions
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now