Java Platform 1.2
Beta 4

Interface java.sql.CallableStatement


public abstract interface CallableStatement
extends PreparedStatement

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 <procedure-name>[<arg1>,<arg2>, ...]}
   {call <procedure-name>[<arg1>,<arg2>, ...]}
 

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.

See Also:
Connection.prepareCall(java.lang.String), ResultSet

Method Summary
 Array getArray(int i)
          JDBC 2.0 Get an Array OUT parameter.
 BigDecimal getBigDecimal(int parameterIndex, int scale)
          Deprecated.  
 BigDecimal getBigDecimal(int parameterIndex)
          JDBC 2.0 Get the value of a NUMERIC parameter as a java.math.
 Blob getBlob(int i)
          JDBC 2.0 Get a BLOB OUT parameter.
 boolean getBoolean(int parameterIndex)
          Get the value of a BIT parameter as a Java boolean.
 byte getByte(int parameterIndex)
          Get the value of a TINYINT parameter as a Java byte.
 byte[] getBytes(int parameterIndex)
          Get the value of a SQL BINARY or VARBINARY parameter as a Java byte[]
 Clob getClob(int i)
          JDBC 2.0 Get a CLOB OUT parameter.
 Date getDate(int parameterIndex, Calendar cal)
          Get the value of a SQL DATE parameter as a java.sql.
 Date getDate(int parameterIndex)
          Get the value of a SQL DATE parameter as a java.sql.
 double getDouble(int parameterIndex)
          Get the value of a DOUBLE parameter as a Java double.
 float getFloat(int parameterIndex)
          Get the value of a FLOAT parameter as a Java float.
 int getInt(int parameterIndex)
          Get the value of an INTEGER parameter as a Java int.
 long getLong(int parameterIndex)
          Get the value of a BIGINT parameter as a Java long.
 Object getObject(int i, Map map)
          JDBC 2.0 Returns an object representing the value of OUT parameter @i.
 Object getObject(int parameterIndex)
          Get the value of a parameter as a Java object.
 Ref getRef(int i)
          JDBC 2.0 Get a REF(<structured-type>) OUT parameter.
 short getShort(int parameterIndex)
          Get the value of a SMALLINT parameter as a Java short.
 String getString(int parameterIndex)
          Get the value of a CHAR, VARCHAR, or LONGVARCHAR parameter as a Java String.
 Time getTime(int parameterIndex, Calendar cal)
          Get the value of a SQL TIME parameter as a java.sql.
 Time getTime(int parameterIndex)
          Get the value of a SQL TIME parameter as a java.sql.
 Timestamp getTimestamp(int parameterIndex, Calendar cal)
          Get the value of a SQL TIMESTAMP parameter as a java.sql.
 Timestamp getTimestamp(int parameterIndex)
          Get the value of a SQL TIMESTAMP parameter as a java.sql.
 void registerOutParameter(int parameterIndex, int sqlType, int scale)
          Use this version of registerOutParameter for registering Numeric or Decimal out parameters.
 void registerOutParameter(int parameterIndex, int sqlType)
          Before executing a stored procedure call, you must explicitly call registerOutParameter to register the java.sql.
 boolean wasNull()
          An OUT parameter may have the value of SQL NULL; wasNull reports whether the last value read has this special value.
 
Methods inherited from interface java.sql.PreparedStatement
addBatch , clearParameters , execute , executeQuery , executeUpdate , getMetaData , setArray , setAsciiStream , setBigDecimal , setBinaryStream , setBlob , setBoolean , setByte , setBytes , setCharacterStream , setClob , setDate , setDate , setDouble , setFloat , setInt , setLong , setNull , setObject , setObject , setObject , setRef , setShort , setString , setTime , setTime , setTimestamp , setTimestamp , setUnicodeStream
 
Methods inherited from interface java.sql.Statement
addBatch , cancel , clearBatch , clearWarnings , close , execute , executeBatch , executeQuery , executeUpdate , getConnection , getFetchDirection , getFetchSize , getMaxFieldSize , getMaxRows , getMoreResults , getQueryTimeout , getResultSet , getResultSetConcurrency , getResultSetType , getUpdateCount , getWarnings , setCursorName , setEscapeProcessing , setFetchDirection , setFetchSize , setMaxFieldSize , setMaxRows , setQueryTimeout
 

Method Detail

registerOutParameter

public void registerOutParameter(int parameterIndex,
                                 int sqlType)
                          throws SQLException
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
Throws:
SQLException - if a database-access error occurs.
See Also:
Type

registerOutParameter

public void registerOutParameter(int parameterIndex,
                                 int sqlType,
                                 int scale)
                          throws SQLException
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
Throws:
SQLException - if a database-access error occurs.
See Also:
Type

wasNull

public boolean wasNull()
                throws SQLException
An OUT parameter may have the value of SQL NULL; wasNull reports whether the last value read has this special value.

Note: You must first call getXXX on a parameter to read its value and then call wasNull() to see if the value was SQL NULL.

Returns:
true if the last parameter read was SQL NULL
Throws:
SQLException - if a database-access error occurs.

getString

public String getString(int parameterIndex)
                 throws SQLException
Get the value of a CHAR, VARCHAR, or LONGVARCHAR parameter as a Java String.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is null
Throws:
SQLException - if a database-access error occurs.

getBoolean

public boolean getBoolean(int parameterIndex)
                   throws SQLException
Get the value of a BIT parameter as a Java boolean.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is false
Throws:
SQLException - if a database-access error occurs.

getByte

public byte getByte(int parameterIndex)
             throws SQLException
Get the value of a TINYINT parameter as a Java byte.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is 0
Throws:
SQLException - if a database-access error occurs.

getShort

public short getShort(int parameterIndex)
               throws SQLException
Get the value of a SMALLINT parameter as a Java short.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is 0
Throws:
SQLException - if a database-access error occurs.

getInt

public int getInt(int parameterIndex)
           throws SQLException
Get the value of an INTEGER parameter as a Java int.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is 0
Throws:
SQLException - if a database-access error occurs.

getLong

public long getLong(int parameterIndex)
             throws SQLException
Get the value of a BIGINT parameter as a Java long.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is 0
Throws:
SQLException - if a database-access error occurs.

getFloat

public float getFloat(int parameterIndex)
               throws SQLException
Get the value of a FLOAT parameter as a Java float.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is 0
Throws:
SQLException - if a database-access error occurs.

getDouble

public double getDouble(int parameterIndex)
                 throws SQLException
Get the value of a DOUBLE parameter as a Java double.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is 0
Throws:
SQLException - if a database-access error occurs.

getBigDecimal

public BigDecimal getBigDecimal(int parameterIndex,
                                int scale)
                         throws SQLException
Deprecated.  
Get the value of a NUMERIC parameter as a java.math.BigDecimal object.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
scale - a value greater than or equal to zero representing the desired number of digits to the right of the decimal point
Returns:
the parameter value; if the value is SQL NULL, the result is null
Throws:
SQLException - if a database-access error occurs.

getBytes

public byte[] getBytes(int parameterIndex)
                throws SQLException
Get the value of a SQL BINARY or VARBINARY parameter as a Java byte[]
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is null
Throws:
SQLException - if a database-access error occurs.

getDate

public Date getDate(int parameterIndex)
             throws SQLException
Get the value of a SQL DATE parameter as a java.sql.Date object
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is null
Throws:
SQLException - if a database-access error occurs.

getTime

public Time getTime(int parameterIndex)
             throws SQLException
Get the value of a SQL TIME parameter as a java.sql.Time object.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is null
Throws:
SQLException - if a database-access error occurs.

getTimestamp

public Timestamp getTimestamp(int parameterIndex)
                       throws SQLException
Get the value of a SQL TIMESTAMP parameter as a java.sql.Timestamp object.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is null
Throws:
SQLException - if a database-access error occurs.

getObject

public Object getObject(int parameterIndex)
                 throws SQLException
Get the value of a parameter as a Java object.

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. JDBC 2.0 The behavior of method getObject() is extended to materialize data of SQL user-defined types. When the OUT parameter @i is a UDT value, the behavior of this method is as if it were a call to: getObject(i, this.getConnection().getTypeMap())

Parameters:
parameterIndex - The first parameter is 1, the second is 2, ...
Returns:
A java.lang.Object holding the OUT parameter value.
Throws:
SQLException - if a database-access error occurs.
See Also:
Types

getBigDecimal

public BigDecimal getBigDecimal(int parameterIndex)
                         throws SQLException
JDBC 2.0 Get the value of a NUMERIC parameter as a java.math.BigDecimal object.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value (full precision); if the value is SQL NULL, the result is null
Throws:
SQLException - if a database-access error occurs.

getObject

public Object getObject(int i,
                        Map map)
                 throws SQLException
JDBC 2.0 Returns an object representing the value of OUT parameter @i. Use the @map to determine the class from which to construct data of SQL structured and distinct types.
Parameters:
i - the first parameter is 1, the second is 2, ...
map - the mapping from SQL type names to Java classes
Returns:
a java.lang.Object holding the OUT parameter value.
Throws:
SQLException - if a database-access error occurs.

getRef

public Ref getRef(int i)
           throws SQLException
JDBC 2.0 Get a REF(<structured-type>) OUT parameter.
Parameters:
i - the first parameter is 1, the second is 2, ...
Returns:
an object representing data of an SQL REF Type
Throws:
SQLException - if a database-access error occurs.

getBlob

public Blob getBlob(int i)
             throws SQLException
JDBC 2.0 Get a BLOB OUT parameter.
Parameters:
i - the first parameter is 1, the second is 2, ...
Returns:
an object representing a BLOB
Throws:
SQLException - if a database-access error occurs.

getClob

public Clob getClob(int i)
             throws SQLException
JDBC 2.0 Get a CLOB OUT parameter.
Parameters:
i - the first parameter is 1, the second is 2, ...
Returns:
an object representing a CLOB
Throws:
SQLException - if a database-access error occurs.

getArray

public Array getArray(int i)
               throws SQLException
JDBC 2.0 Get an Array OUT parameter.
Parameters:
i - the first parameter is 1, the second is 2, ...
Returns:
an object representing an SQL array
Throws:
SQLException - if a database-access error occurs.

getDate

public Date getDate(int parameterIndex,
                    Calendar cal)
             throws SQLException
Get the value of a SQL DATE parameter as a java.sql.Date object
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is null
Throws:
SQLException - if a database-access error occurs.

getTime

public Time getTime(int parameterIndex,
                    Calendar cal)
             throws SQLException
Get the value of a SQL TIME parameter as a java.sql.Time object.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is null
Throws:
SQLException - if a database-access error occurs.

getTimestamp

public Timestamp getTimestamp(int parameterIndex,
                              Calendar cal)
                       throws SQLException
Get the value of a SQL TIMESTAMP parameter as a java.sql.Timestamp object.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
Returns:
the parameter value; if the value is SQL NULL, the result is null
Throws:
SQLException - if a database-access error occurs.

Java Platform 1.2
Beta 4

Submit a bug or feature
Submit comments/suggestions about new javadoc look
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This documentation was generated with a post-Beta4 version of Javadoc.