aspose file tools*
The moose likes JDBC and the fly likes  PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark " PreparedStatement" Watch " PreparedStatement" New topic
Author

PreparedStatement

francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 165

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

Joined: Apr 18, 2009
Posts: 2234

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 .


Save India From Corruption - Anna Hazare.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1665
    
    7

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.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
 
 
subject: PreparedStatement
 
Similar Threads
Simple SQL question
encrypted username breaks sql
how to get dynamic data from the oracle back end
How to construct the SQL statement ?
JDBC problem:Too few parameters. Expected 1