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 Statement v/s 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 "Statement v/s PreparedStatement " Watch "Statement v/s PreparedStatement " New topic

Statement v/s PreparedStatement

Abhijit Kangale
Ranch Hand

Joined: Sep 17, 2009
Posts: 39
Hi all,

PreparedStatement is called pre compiled statement but Statement is not why?
How PreparedStatement is pre compiled?

M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 160
In case of PreparedStatement, the skeleton of an SQL statement is prepared/compiled during it's creation/instantiation.
For e.g.

place holders (? marks) are used instead of actual values, this skeleton is compiled before going to execute with the actual values, as follows:

In case of Statement, no SQL statement is prepared/compiled during creation/instantiation.
For e.g.
Later, the SQL statement with values together executed as follows:

I agree. Here's the link:
subject: Statement v/s PreparedStatement
jQuery in Action, 3rd edition