File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes  PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark " PreparedStatement" Watch " PreparedStatement" New topic


francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 169

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

Joined: Mar 10, 2008
Posts: 1951

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.
I agree. Here's the link:
subject: PreparedStatement
It's not a secret anymore!