When you use this method, the returned CallableStatement
object can be used to query for a ResultSet (This require that
the database-stored procedure must return a DB table)
that can be updateable and can be scrollable.

This will create a CallableStatement object as the previous one.
Use this method when you also want to decide whether
you want the resultset to stay open (resultSetHoldability) after a transaction is committed.
(Only available in JDBC 3.0)

The resultSetHoldability constant will indicates that a open ResultSet objects
shall remain open or closed when the current transaction is committed.

The CallableStatement interface extends
the PreparedStatement interface,
which means that the CallableStatement interface can use parametric placeholders for
values in the SQL statement, which is given as first parameter to the
prepareCall() method.

Steps to create and execute a SQL statement using
prepareCall() method are:

When you have got a database Connection, create a CallableStatement
with one of the prepareCall() methods above
where the SQL statement contains a call to a known database-stored procedure.

If any parametric placeholder exists in your SQL statement which
can result in an output from the database-stored procedure you will call, then you must
register those placeholders with a type that you will found in the java.sql.Types
class (look in the API for Types).
This registering is done by using one of the
registerOutPutParameter() method, which
you can find in the
RegisterOutPutParameter methods
table below.

If the SQL statement, that contains the call to a database-stored procedure,
has any input type placeholders, then you must set those values
with the right type
setXXX()
method, which you can find in the table below.

Now you can execute one of the
Execute methods
found in the table below. Which method you should
choose depend on what you expect in return from the
calling database-stored procedure.

The CallableStatement object will now contain
requested database data, which can be retrieved with the
getXXX() methods
(look in the table below),
or if you used the executeQuery() method you can
retrieve data using any of the
getXXX() methods
in the ResultSet.

Example code:

// The query should be on the form { call procedurename }
String SQL = "{ ? = call getTotalcost(?,?) }"// Placeholders (?) index: 1 2 3
CallableStatement cs = conn.prepareCall(sql);
// Placeholder that result in an output from the // procedure should be registered with a one of the // types found in the java.sql.Types class
cs.registerOutParameter(1, java.sql.Types.DOUBLE);
cs.registerOutParameter(2, java.sql.Types.STRING);
// set some values for the procedure
cs.setString(3, 60);
cs.execute();

Summary of execute methods in CallableStatement interface.

When you have got a java.sql.CallableStatement
object, several methods in that interface can be used to execute
a parameterized SQL statement against the database.

Execute methods in
java.sql.CallableStatement
interface to use:

Methods in CallableStatement interface

Description

int executeUpdate()

Executes the SQL procedure call statement in this
CallableStatement object. The database procedure must do an SQL Data Manipulation
Language (DML) statement, such as INSERT, UPDATE or DELETE;
or an SQL statement that returns nothing, such as a DDL statement.

ResultSet executeQuery()

Executes the SQL procedure call statement
in this CallableStatement object and returns the ResultSet object
returned by the query contained in the database procedure.

boolean execute()

Executes the SQL procedure call statement in this
CallableStatement object. The database procedure
may be contain any kind of SQL statement.
This method is in most cases the preferred.