What are the advantages of callable statements over prepared statements?

Showing Answers 1 - 20 of 20 Answers

saradakonda

  • Aug 29th, 2006
 

A CallableStatement is a way to execute stored procedures in a JDBC-compatible database.

A PreparedStatement, in contrast to a CallableStatement, is used for SQL statements that are executed multiple times with different values. For instance, you might want to insert several values into a table, one after another. The advantage of the PreparedStatement is that it is pre-compiled, reducing the overhead of parsing SQL statements on every execution. For Example

  ps = c.prepareStatement("INSERT INTO authors VALUES (?, ?, ?)");
  ps.setInt(1, 495);
  ps.setString(2, "Light-Williams");
  ps.setString(3, "Corwin");ps.executeUpdate();

  Was this answer useful?  Yes

In case a Statement needs to be executed many times, prepared statement is used as it will normally reduce execution time.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.

  Was this answer useful?  Yes

Yogvinder

  • Dec 4th, 2006
 

If i am not mistaken, all the diffrences stated don't compare CallableStatement with PreparedStatement.

  Was this answer useful?  Yes

S. Dada Khalander

  • Dec 14th, 2006
 

1. Callable statements are used to exeute stored procedures...

2. Its does not contain a stored procedure.. Its just makes a call to execute stored procedures..

3. By using callable statements we can separate the application logic and the business logic.

  Was this answer useful?  Yes

Vamshi

  • Feb 2nd, 2007
 

CallableStatement inherits Statement methods, which deal with SQL statements in general, and it also inherits PreparedStatement methods, which deal with IN parameters. All of the methods defined in CallableStatement deal with OUT parameters>OUT parameters or the output aspect of INOUT parameters: registering the JDBC types of the OUT parameters, retrieving values from them, or checking whether a returned value was JDBC NULL. Whereas the getter methods defined in ResultSet (getString, getLong, and so on) retrieve values from a result set, the getter methods in CallableStatement retrieve values from the OUT parameters and/or return value of a stored procedure.

  Was this answer useful?  Yes

Nowfaldaan

  • Mar 9th, 2007
 

Statement:  to execute a single query one time

preparedstatement: to execute a single query multiple times(here the statement will be precompiled and will get good performance)

Collable statement : to execute multiple query multiple times(we are using collable statement to execute procedure it's also precompiled)

  Was this answer useful?  Yes

Mukesh Luhar

  • Dec 5th, 2014
 

Prepared : use when you plan to use the SQL statement many times.
Callable : use when you want to access database stored procedures.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions