Interface CallableStatement

public interface CallableStatement extends Object extends PreparedStatement

Callable statements are used to call SQL stored procedures in a standard way for all DBMSs. Escape syntax is used for procedures that return a result parameter and those that don’t return a parameter. If the procedure returns a result, the result parameter must be registered as an OUT parameter.

The set methods inherited from PreparedStatement are used to set IN parameter values. The type of all OUT parameters must be registered prior to executing the stored procedure. Their values are retrieved via the get methods provided in this section.

A Callable statement can return a ResultSet or multiple ResultSets. Multiple ResultSets are handled using methods inherited from Statement. The OUT param-eters must always be retrieved after processing ResultSets and update counts, if any.

The following shows the JDBC format of SQL queries that call a stored procedure:

{?= call <PROCEDURE-NAME>[<ARG1>,<ARG2> , ...]} {call <PROCEDURE-NAME>[<ARG1>,<ARG2> , ...]}

See also: prepareCall, ResultSet

Methods

getArray

public Array getArray(int parameterIndex) throws SQLException

This gets the value of a JDBC ARRAY parameter as an Array object.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The parameter value as an Array object

getBigDecimal

public BigDecimal getBigDecimal(int parameterIndex) throws SQLException

This gets the value of an OUT parameter of type SQL NUMERIC as a java.math.BigDecimal object, with as many decimal digits as the parameter value contains.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; null if its value is SQL NULL

getBigDecimal

public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException

This gets the value of an OUT parameter of type SQL NUMERIC as a java.math.BigDecimal object.

Parameters:

parameterIndex:

The parameter index begins at 1.

scale:

A positive value representing the decimal precision.

Returns: The OUT parameter value; null if its value is SQL NULL

getBlob

public Blob getBlob(int parameterIndex) throws SQLException

This gets the value of a JDBC BLOB parameter as a Blob object.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The parameter value as a Blob object

getBoolean

public boolean getBoolean(int parameterIndex) throws SQLException

This gets the value of an OUT parameter of type SQL BIT as a Java boolean.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; false if the value is SQL NULL

getByte

public byte getByte(int parameterIndex) throws SQLException

This gets the value of an OUT parameter of type SQL TINYINT as a Java byte.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; 0 if the value is SQL NULL

getBytes

public byte[] getBytes(int parameterIndex) throws SQLException

This gets the value of an OUT parameter of type SQL BINARY or VARBINARY as a Java byte[].

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; null if the value is SQL NULL

getClob

public Clob getClob(int parameterIndex) throws SQLException

This gets the value of a JDBC CLOB parameter as a Clob object.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The parameter value as a Clob object

getDate

public Date getDate(int parameterIndex) throws SQLException

This gets the value of an OUT parameter of type SQL DATE as a java.sql.Date object.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; null if the value is SQL NULL

getDouble

public double getDouble(int parameterIndex) throws SQLException

This gets the value of an OUT parameter of type SQL DOUBLE as a Java double.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; 0 if the value is SQL NULL

getFloat

public float getFloat(int parameterIndex) throws SQLException 

This gets the value of an OUT parameter of type SQL FLOAT as a Java float.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; 0 if the value is SQL NULL

getInt

public int getInt(int parameterIndex) throws SQLException

This gets the value of an OUT parameter of type SQL INTEGER as a Java int.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; 0 if the value is SQL NULL

getLong

public long getLong(int parameterIndex) throws SQLException

This gets the value of an OUT parameter of type SQL BIGINT as a Java long.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; 0 if the value is SQL NULL

getObject

public Object getObject(int parameterIndex) throws SQLException

This gets the value of an OUT parameter as a Java object.

The object type corresponds to the SQL type that was registered for this param-eter using registerOutParameter().

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: An Object containing the OUT parameter value

See also: Types

getObject

public Object getObject(int parameterIndex, java.util.Map map) throws SQLException

This gets the value of an OUT parameter as a Java object using a map for custom mapping.

The object type corresponds to the SQL type that was registered for this param-eter using registerOutParameter().

Parameters:

parameterIndex:

The parameter index begins at 1.

map:

The mapping from SQL type names to Java classes.

Returns: An Object containing the OUT parameter value

See also: Types

getRef

public Ref getRef(int parameterIndex) throws SQLException

This gets the value of a JDBC REF parameter as a Ref object.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The parameter value as a Ref object or null if the value is SQL NULL

getShort

public short getShort(int parameterIndex) throws SQLException

This gets the value of an OUT parameter of type SQL SMALLINT as a Java short.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; 0 if the value is SQL NULL

getString

public String getString(int parameterIndex) throws SQLException

This gets the value of an OUT parameter of type SQL CHAR, VARCHAR, or LONGVARCHAR as a Java String.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; null if the value is SQL NULL

getTime

public Time getTime(int parameterIndex) throws SQLException

This gets the value of an OUT parameter of type SQL TIME as a java.sql.Time object.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; null if the value is SQL NULL

getTimestamp

public Timestamp getTimestamp(int parameterIndex) throws SQLException 

This gets the value of an OUT parameter of type SQL TIMESTAMP as a java.sql. Timestamp object.

Parameters:

parameterIndex:

The parameter index begins at 1.

Returns: The OUT parameter value; null if the value is SQL NULL

getURL

public java.net.URL getURL(int parameterIndex) throws SQLException, java.net.MalformedURLException

This gets the value of a DATALINK parameter as a java.net.URL object.

Parameters:

parameterIndex:

The parameter index begins at 1.

registerOutParameter

public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException

The registerOutParameter() method must be called before executing a stored procedure to register the java.sql.Type of each OUT parameter. This type is used to retrieve the OUT parameter value with the appropriate getXXX() method.

Parameters:

parameterIndex:

The parameter index begins at 1.

sqlType:

The SQL type code defined by java.sql.Types.

See also: Type

registerOutParameter

public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException

This registerOutParameter() method is used for registering Numeric or Decimal OUT parameters.

Parameters:

parameterIndex:

The parameter index begins at 1.

sqlType:

java.sql.Type.NUMERIC or java.sql.Type. DECIMAL.

scale:

A positive value representing the desired number of decimal digits.

See also: Numeric, Type

registerOutParameter

public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException

This registerOutParameter() method is used for registering REF parameters.

Parameters:

parameterIndex:

The parameter index begins at 1.

sqlType:

A value from Types.

typeName:

The fully qualified name of a SQL structured type.

setArray

public void setArray(String parameterName, Array x) throws SQLException

This sets the parameter to the given Array object.

Parameters:

parameterName:

The name of the parameter

x:

The Array object that maps a SQL ARRAY value

setAsciiStream

public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException

setAsciiStream() is used to set very large LONGVARCHAR parameters. You can send the ASCII data using a java.io.inputStream. JDBC stops sending data when it reaches EOF (end of file). ASCII characters are converted to the database CHAR format.

Parameters:

parameterName:

The name of the parameter

x:

The ASCII data stream

length:

The data length in bytes

setBigDecimal

public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException

This supplies a java.math.BigDecimal value that will be converted to a SQL NUMERIC value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setBinaryStream

public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException

setBinaryStream() is used to set very large LONGVARBINARY parameters. You can send the binary data using a java.io.inputStream. JDBC stops sending data when it reaches EOF (end of file).

Parameters:

parameterName:

The name of the parameter

x:

The binary data stream

length:

The data length in bytes

setBlob

public void setBlob(String parameterName, Blob x) throws SQLException

This sets the parameter to the given Blob object.

Parameters:

parameterName:

The name of the parameter

x:

A Blob object that maps a SQL BLOB value

setBoolean

public void setBoolean(String parameterName, boolean x) throws SQLException

This supplies a Java boolean value that is converted to a SQL BIT value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setByte

public void setByte(String parameterName, byte x) throws SQLException

This supplies a Java byte value that is converted to a SQL TINYINT value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setBytes

public void setBytes(String parameterName, byte x[]) throws SQLException

This supplies a Java array of bytes that is converted to a SQL VARBINARY or LONGVARBINARY when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setCharacterStream

public void setCharacterStream(String parameterName, java.io.Reader reader, int length) throws SQLException

This sets a Unicode character stream to the designated parameter.

Parameters:

parameterName:

The name of the parameter

reader:

The java.io.Reader object containing the Unicode data

length:

The number of characters in the stream

setClob

public void setClob(String parameterName, Clob x) throws SQLException

This sets the parameter to the given Clob object.

Parameters:

parameterName:

The name of the parameter

x:

The Clob object that maps a SQL CLOB value

setDate

public void setDate(String parameterName, Date x) throws SQLException

This supplies a java.sql.Date value that is converted to a SQL DATE value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setDate

public void setDate(String parameterName, Date x, java.util.Calendar cal) throws SQLException 

This supplies a java.sql.Date value that is converted to a SQL DATE value when sent to the database using the calendar provided as parameter.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

cal:

The Calendar object that the driver will use to construct the date

setDouble

public void setDouble(String parameterName, double x) throws SQLException

This supplies a Java double value that is converted to a SQL DOUBLE value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setFloat

public void setFloat(String parameterName, float x) throws SQLException

This supplies a Java float value that is converted to a SQL FLOAT value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setInt

public void setInt(String parameterName, int x) throws SQLException

This supplies a Java int value that is converted to a SQL INTEGER value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setLong

public void setLong(String parameterName, long x) throws SQLException 

This supplies a Java long value that is converted to a SQL BIGINT value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setNull

public void setNull(String parameterName, int sqlType) throws SQLException

This supplies a SQL NULL value. The parameter’s SQL type must be supplied.

Parameters:

parameterName:

The name of the parameter

sqlType:

A SQL type code (see java.sql.Types)

setNull

public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException

This supplies a SQL NULL value. The parameter’s SQL type must be supplied as well as the fully qualified SQL Type name for greater portability.

Parameters:

paramIndex:

The parameter index begins at 1.

sqlType:

A value from java.sql.Types.

typeName:

The fully qualified name of a SQL user-defined type. It is ignored if the parameter isn’t a user-defined type or REF type.

setObject

public void setObject(String parameterName, Object x,int targetSqlType,  int scale) throws SQLException

This supplies a parameter value using an object that is converted to the targetSqlType when sent to the database. Data types may be passed using a driver-specific Java type and using java.sql.types.OTHER as targetSqlType.

Parameters:

parameterName:

The name of the parameter.

x:

The object containing the input parameter value.

targetSqlType:

A SQL type code (see java.sql.Types).

scale:

The number of digits after the decimal for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types. This is ignored for other types.

See also: Types

setObject

public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException

This enables you to use an object as a parameter value and to specify a target SQL type.

Parameters:

parameterName:

The name of the parameter

x:

The object containing the input parameter value

targetSqlType:

The SQL type to which this object must be converted

setObject

public void setObject(String parameterName, Object x) throws SQLException

This enables you to use an object as a parameter value but uses the standard mapping from Java object types to SQL types.

Parameters:

parameterName:

The name of the parameter

x:

The object containing the input parameter value

setRef

public void setRef(String parameterName, Ref x) throws SQLException

This sets the parameter to the given REF value.

Parameters:

parameterName:

The name of the parameter

x:

A SQL REF value

setShort

public void setShort(String parameterName, short x) throws SQLException

This supplies a Java short value that is converted to a SQL SMALLINT value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setString

public void setString(String parameterName, String x) throws SQLException 

This supplies a Java String value that is converted to a SQL VARCHAR or LONGVARCHAR value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setTime

public void setTime(String parameterName, Time x) throws SQLException

This supplies a java.sql.Time value that is converted to a SQL TIME value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setTime

public void setTime(String parameterName, Time x, java.util.Calendar cal) throws SQLException

This supplies a java.sql.Time value that is converted to a SQL TIME value when sent to the database using the Calendar object provided as a parameter.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

cal:

The Calendar object that the driver will use to construct the time

setTimestamp

public void setTimestamp(String parameterName, Timestamp x) throws SQLException

This supplies a java.sql.Timestamp value that is converted to a SQL TIMESTAMP value when sent to the database.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

setTimestamp

public void setTimestamp(String parameterName, Timestamp x, java.util.Calendar cal) throws SQLException 

This supplies a java.sql.Timestamp value that is converted to a SQL TIMESTAMP value when sent to the database using the Calendar object provided as a parameter.

Parameters:

parameterName:

The name of the parameter

x:

The parameter value

cal:

The Calendar object that the driver will use to construct the timestamp

setUnicodeStream

public void setUnicodeStream(String parameterName, InputStream x,int length) throws SQLException

setUnicodeStream() is used to set very large LONGVARCHAR parameters. The Unicode data may be sent using a java.io.inputStream. JDBC stops sending data when it reaches EOF (end of file). Unicode characters are converted to the database CHAR format.

Parameters:

parameterName:

The name of the parameter

x:

The Unicode data stream

length:

The data length in bytes

setURL

public void setURL(String parameterName, java.net.URL x) throws SQLException

This sets the parameter to a java.net.URL value. This value is converted to a SQL DATALINK when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

wasNull

public boolean wasNull() throws SQLException

This method reports whether the last value read was a SQL NULL. A getXXX() must be invoked first.

Returns: true if the last parameter read was SQL NULL



JDBC 3. 0. JAVA Database Connectivity
JDBC 3: Java Database Connectivity
ISBN: 0764548751
EAN: 2147483647
Year: 2002
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net