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 Rangarajan Balasubramanian 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 "Rangarajan Balasubramanian" Watch "Rangarajan Balasubramanian" New topic

Rangarajan Balasubramanian

Rangarajan Balasubramanian

Joined: Jun 10, 2005
Posts: 9
When we use prepared statement and when we use callable statement?Give me a scenario
Sathya Prabhu

Joined: Mar 10, 2006
Posts: 12
The main feature of a PreparedStatement object is that, unlike a Statement object, it is given an SQL statement when it is created. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement 's SQL statement without having to compile it first.

A CallableStatement,on the other hand provides a way to call stored procedures in a standard way for all DBMSs. A stored procedure is stored in a database; the call to the stored procedure is what a CallableStatement object contains.

Hope this will help out in differentiating!!!

Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3640
Give proper subject to your thread.

My blood is tested +ve for Java.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Prepared statements are very smart about handling parameters, too. If you build up a complete SQL statement as a string you have to worry about escaping special characters, formatting dates, all kinds of stuff that a prepared statement will do for you.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Rangarajan Balasubramanian
It's not a secret anymore!