Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PreparedStatement

 
francis varkey
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
I have few doubts about

1) What are the advantages of Statement over PreparedStatement
2) From where the PreparedStatement is compiled ?
3) From where the PreparedStatement is executing ?

Thank you,
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Statement is common , i will tell you when to use PreparedStatement

Use PreparedStatement , when you want to execute the Same Query number of Times

Assume this scenario you have a lot of Data in HashMap with different username and password values in it , and now you want to insert them in Database .

So first form a Insert Query in PreparedStatement and then



Now i think you can assume a scenario like this .
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Query optimization by the database. This also happens in case of a PreparedStatement, but because it uses bind variables, optimization can be more limited. In practice the cost of recompilation usually outweighs the performance gained by further optimizing the query.
2) The database prepares and caches the execution plan of the SQL query that results from the PreparedStatement.
3) The database runs the execution plan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic