CallableStatement is used to execute SQL stored procedures.
JDBC provides a stored procedure SQL escape that allows stored
procedures to be called in a standard way for all RDBMS's. This
escape syntax has one form that includes a result parameter and one
that does not. If used, the result parameter must be registered as
an OUT parameter. The other parameters may be used for input,
output or both. Parameters are refered to sequentially, by
number. The first parameter is 1.
{?= call [,, ...]}
{call [,, ...]}
IN parameter values are set using the set methods inherited from
PreparedStatement. The type of all OUT parameters must be
registered prior to executing the stored procedure; their values
are retrieved after execution via the get methods provided here.
A Callable statement may return a ResultSet or multiple
ResultSets. Multiple ResultSets are handled using operations
inherited from Statement.
For maximum portability, a call's ResultSets and update counts
should be processed prior to getting the values of output
parameters.
Before executing a stored procedure call, you must explicitly
call registerOutParameter to register the java.sql.Type of each
out parameter.
Note: When reading the value of an out parameter, you
must use the getXXX method whose Java type XXX corresponds to the
parameter's registered SQL type.
Parameters:
parameterIndex - the first parameter is 1, the second is 2,...
sqlType - SQL type code defined by java.sql.Types;
for parameters of type Numeric or Decimal use the version of
registerOutParameter that accepts a scale value
Use this version of registerOutParameter for registering
Numeric or Decimal out parameters.
Note: When reading the value of an out parameter, you
must use the getXXX method whose Java type XXX corresponds to the
parameter's registered SQL type.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
sqlType - use either java.sql.Type.NUMERIC or java.sql.Type.DECIMAL
scale - a value greater than or equal to zero representing the
desired number of digits to the right of the decimal point
This method returns a Java object whose type coresponds to the SQL
type that was registered for this parameter using registerOutParameter.
Note that this method may be used to read
datatabase-specific, abstract data types. This is done by
specifying a targetSqlType of java.sql.types.OTHER, which
allows the driver to return a database-specific Java type.
Parameters:
parameterIndex - The first parameter is 1, the second is 2, ...
Returns:
A java.lang.Object holding the OUT parameter value.