|
Oracle10g JDBC | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This interface extends the OraclePreparedStatement
(which
extends the OracleStatement
interface) and incorporates standard
JDBC callable statement functionality. It is used to execute SQL stored
procedure.
Oracle JDBC drivers support execution of PL/SQL stored procedures and anonymous blocks. They support both SQL92 escape syntax and Oracle PL/SQL block syntax. The following PL/SQL calls would work with any Oracle JDBC driver:
// SQL92 syntax CallableStatement cs1 = conn.prepareCall ( "{call proc (?,?)}" ) ; // stored proc CallableStatement cs2 = conn.prepareCall ( "{? = call func (?,?)}" ) ; // stored func // Oracle PL/SQL block syntax CallableStatement cs3 = conn.prepareCall ( "begin proc (?,?); end;" ) ; // stored proc CallableStatement cs4 = conn.prepareCall ( "begin ? := func(?,?); end;" ) ; // stored func
As an example of using Oracle syntax, here is a PL/SQL code snippet that creates a stored function. The PL/SQL function gets a character sequence and concatenates a suffix to it:
create or replace function foo (val1 char) return char as begin return val1 || 'suffix'; end;
Your invocation call in your JDBC program should look like:
Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger"); CallableStatement cs = conn.prepareCall ("begin ? := foo(?); end;"); cs.registerOutParameter(1,Types.CHAR); cs.setString(2, "aa"); cs.executeUpdate(); String result = cs.getString(1);
Connection.prepareCall
Field Summary |
Fields inherited from interface java.sql.Statement |
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO |
Fields inherited from interface oracle.jdbc.OraclePreparedStatement |
FORM_CHAR, FORM_NCHAR |
Fields inherited from interface oracle.jdbc.OracleStatement |
EXPLICIT, IMPLICIT, NEW |
Method Summary | |
java.lang.Object |
getAnyDataEmbeddedObject(int parameterIndex)
Retrieves data of an embedded object within AnyData |
ARRAY |
getARRAY(int parameterIndex)
Retrieves data into an oracle.sql.ARRAY object. |
java.io.InputStream |
getAsciiStream(int parameterIndex)
Retrieves data into an java.io.InputStream object. |
BFILE |
getBFILE(int parameterIndex)
Retrieves data into an oracle.sql.BFILE object. |
java.io.InputStream |
getBinaryStream(int parameterIndex)
Retrieves data into an java.io.InputStream object. |
BLOB |
getBLOB(int parameterIndex)
Retrieves data into an oracle.sql.BLOB object. |
CHAR |
getCHAR(int parameterIndex)
Retrieves data into an oracle.sql.CHAR object. |
java.io.Reader |
getCharacterStream(int parameterIndex)
Retrieves data into an java.io.Reader object. |
CLOB |
getCLOB(int parameterIndex)
Retrieves data into an oracle.sql.CLOB object. |
java.sql.ResultSet |
getCursor(int parameterIndex)
Retrieves data into an java.sql.ResultSet object. |
java.lang.Object |
getCustomDatum(int parameterIndex,
CustomDatumFactory factory)
Deprecated. |
DATE |
getDATE(int parameterIndex)
Retrieves data into an oracle.sql.DATE object. |
INTERVALDS |
getINTERVALDS(int parameterIndex)
Retrieves data into an oracle.sql.INTERVALDS object. |
INTERVALYM |
getINTERVALYM(int parameterIndex)
Retrieves data into an oracle.sql.INTERVALYM object. |
NUMBER |
getNUMBER(int parameterIndex)
Retrieves data into an oracle.sql.NUMBER object. |
OPAQUE |
getOPAQUE(int parameterIndex)
Retrieves data into an oracle.sql.OPAQUE object. |
Datum |
getOracleObject(int parameterIndex)
Retrieves data into an oracle.sql.Datum object. |
Datum[] |
getOraclePlsqlIndexTable(int paramIndex)
Oracle OCI driver specific. |
java.lang.Object |
getORAData(int parameterIndex,
ORADataFactory factory)
|
java.lang.Object |
getPlsqlIndexTable(int paramIndex)
Get the value of a PLSQL index table parameter as a Java array. |
java.lang.Object |
getPlsqlIndexTable(int paramIndex,
java.lang.Class primitiveType)
Oracle OCI driver specific. |
RAW |
getRAW(int parameterIndex)
Retrieves data into an oracle.sql.RAW object. |
REF |
getREF(int parameterIndex)
Retrieves data into an oracle.sql.REF object. |
ROWID |
getROWID(int parameterIndex)
Retrieves data into an oracle.sql.ROWID object. |
STRUCT |
getSTRUCT(int parameterIndex)
Retrieves data into an oracle.sql.STRUCT object. |
TIMESTAMP |
getTIMESTAMP(int paramIdx)
Retrieves data into an oracle.sql.TIMESTAMP object. |
TIMESTAMPLTZ |
getTIMESTAMPLTZ(int paramIdx)
Retrieves data into an oracle.sql.TIMESTAMPLTZ object. |
TIMESTAMPTZ |
getTIMESTAMPTZ(int paramIdx)
Retrieves data into an oracle.sql.TIMESTAMPTZ object. |
java.io.InputStream |
getUnicodeStream(int parameterIndex)
Retrieves data into an java.io.InputStream object. |
void |
registerIndexTableOutParameter(int paramIndex,
int maxLen,
int elemSqlType,
int elemMaxLen)
Oracle OCI driver specific. |
void |
registerOutParameter(int paramIndex,
int sqlType,
int scale,
int maxLength)
Special Oracle version of registerOutParameter for registering CHAR, VARCHAR, LONG, RAW and LONG RAW columns. |
void |
registerOutParameter(java.lang.String parameterName,
int sqlType,
int scale,
int maxLength)
Special Oracle version of registerOutParameter for registering CHAR, VARCHAR, LONG, RAW and LONG RAW columns. |
void |
registerOutParameterBytes(int paramIndex,
int sqlType,
int scale,
int maxLength)
Special Oracle version of registerOutParameter for registering CHAR, VARCHAR, LONG, RAW and LONG RAW columns. |
void |
registerOutParameterChars(int paramIndex,
int sqlType,
int scale,
int maxLength)
Special Oracle version of registerOutParameter for registering CHAR, VARCHAR, LONG, RAW and LONG RAW columns. |
int |
sendBatch()
Send the sets of parameters batched (for Oracle-style batching only). |
void |
setBinaryDouble(java.lang.String parameterName,
BINARY_DOUBLE x)
Sets the designated parameter to the given oracle.sql.BINARY_FLOAT
value. |
void |
setBinaryFloat(java.lang.String parameterName,
BINARY_FLOAT x)
Sets the designated parameter to the given oracle.sql.BINARY_FLOAT value. |
void |
setExecuteBatch(int nrows)
Set the batch value (for Oracle-style batching only). |
void |
setStringForClob(java.lang.String parameterName,
java.lang.String x)
Sets the designated parameter to the given Java String value. |
Methods inherited from interface java.sql.CallableStatement |
getArray, getArray, getBigDecimal, getBigDecimal, getBigDecimal, getBlob, getBlob, getBoolean, getBoolean, getByte, getByte, getBytes, getBytes, getClob, getClob, getDate, getDate, getDate, getDate, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getLong, getLong, getObject, getObject, getObject, getObject, getRef, getRef, getShort, getShort, getString, getString, getTime, getTime, getTime, getTime, getTimestamp, getTimestamp, getTimestamp, getTimestamp, getURL, getURL, registerOutParameter, registerOutParameter, registerOutParameter, registerOutParameter, registerOutParameter, registerOutParameter, setAsciiStream, setBigDecimal, setBinaryStream, setBoolean, setByte, setBytes, setCharacterStream, setDate, setDate, setDouble, setFloat, setInt, setLong, setNull, setNull, setObject, setObject, setObject, setShort, setString, setTime, setTime, setTimestamp, setTimestamp, setURL, wasNull |
Methods inherited from interface java.sql.PreparedStatement |
addBatch, clearParameters, execute, executeQuery, executeUpdate, getMetaData, getParameterMetaData, setArray, setAsciiStream, setBigDecimal, setBinaryStream, setBlob, setBoolean, setByte, setBytes, setCharacterStream, setClob, setDate, setDate, setDouble, setFloat, setInt, setLong, setNull, setNull, setObject, setObject, setObject, setRef, setShort, setString, setTime, setTime, setTimestamp, setTimestamp, setUnicodeStream, setURL |
Methods inherited from interface java.sql.Statement |
addBatch, cancel, clearBatch, clearWarnings, close, execute, execute, execute, execute, executeBatch, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setQueryTimeout |
Methods inherited from interface oracle.jdbc.OracleStatement |
clearDefines, closeWithKey, creationState, defineColumnType, defineColumnType, defineColumnType, defineColumnType, defineColumnTypeBytes, defineColumnTypeChars, getRowPrefetch, isNCHAR, setResultSetCache, setRowPrefetch |
Method Detail |
public ARRAY getARRAY(int parameterIndex) throws java.sql.SQLException
oracle.sql.ARRAY
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
ARRAY
java.sql.SQLException
- if an error occurs (conversion or database-access error)public java.io.InputStream getAsciiStream(int parameterIndex) throws java.sql.SQLException
java.io.InputStream
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
java.io.InputStream
java.sql.SQLException
- if an error occurs (conversion or database-access error)public BFILE getBFILE(int parameterIndex) throws java.sql.SQLException
oracle.sql.BFILE
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.BFILE
java.sql.SQLException
- if an error occurs (conversion or database-access error)public java.io.InputStream getBinaryStream(int parameterIndex) throws java.sql.SQLException
java.io.InputStream
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
java.io.InputStream
java.sql.SQLException
- if an error occurs (conversion or database-access error)public BLOB getBLOB(int parameterIndex) throws java.sql.SQLException
oracle.sql.BLOB
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.BLOB
java.sql.SQLException
- if an error occurs (conversion or database-access error)public CHAR getCHAR(int parameterIndex) throws java.sql.SQLException
oracle.sql.CHAR
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.CHAR
java.sql.SQLException
- if an error occurs (conversion or database-access error)public java.io.Reader getCharacterStream(int parameterIndex) throws java.sql.SQLException
java.io.Reader
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
java.io.Reader
java.sql.SQLException
- if an error occurs (conversion or database-access error)public CLOB getCLOB(int parameterIndex) throws java.sql.SQLException
oracle.sql.CLOB
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.CLOB
java.sql.SQLException
- if an error occurs (conversion or database-access error)public java.sql.ResultSet getCursor(int parameterIndex) throws java.sql.SQLException
java.sql.ResultSet
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
java.sql.ResultSet
java.sql.SQLException
- if an error occurs (conversion or database-access error)public java.lang.Object getCustomDatum(int parameterIndex, CustomDatumFactory factory) throws java.sql.SQLException
parameterIndex
- the first parameter is 1, the second is 2, and so onfactory
-
java.sql.SQLException
- if an error occurs (conversion or database-access error)public java.lang.Object getORAData(int parameterIndex, ORADataFactory factory) throws java.sql.SQLException
parameterIndex
- the first parameter is 1, the second is 2, and so onfactory
-
java.sql.SQLException
- if an error occurs (conversion or database-access error)public java.lang.Object getAnyDataEmbeddedObject(int parameterIndex) throws java.sql.SQLException
parameterIndex
- the first parameter is 1
java.sql.SQLException
- if an error occurs (conversion or database-access
error)public DATE getDATE(int parameterIndex) throws java.sql.SQLException
oracle.sql.DATE
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.DATE
java.sql.SQLException
- if an error occurs (conversion or database-access error)public NUMBER getNUMBER(int parameterIndex) throws java.sql.SQLException
oracle.sql.NUMBER
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.NUMBER
java.sql.SQLException
- if an error occurs (conversion or database-access error)public OPAQUE getOPAQUE(int parameterIndex) throws java.sql.SQLException
oracle.sql.OPAQUE
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.OPAQUE
java.sql.SQLException
- if an error occurs (conversion or database-access error)public Datum getOracleObject(int parameterIndex) throws java.sql.SQLException
oracle.sql.Datum
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.Datum
java.sql.SQLException
- if an error occurs (conversion or database-access error)public RAW getRAW(int parameterIndex) throws java.sql.SQLException
oracle.sql.RAW
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.RAW
java.sql.SQLException
- if an error occurs (conversion or database-access error)public REF getREF(int parameterIndex) throws java.sql.SQLException
oracle.sql.REF
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.REF
java.sql.SQLException
- if an error occurs (conversion or database-access error)public ROWID getROWID(int parameterIndex) throws java.sql.SQLException
oracle.sql.ROWID
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.ROWID
java.sql.SQLException
- if an error occurs (conversion or database-access error)public STRUCT getSTRUCT(int parameterIndex) throws java.sql.SQLException
oracle.sql.STRUCT
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.STRUCT
java.sql.SQLException
- if an error occurs (conversion or database-access error)public INTERVALYM getINTERVALYM(int parameterIndex) throws java.sql.SQLException
oracle.sql.INTERVALYM
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.INTERVALYM
java.sql.SQLException
- if an error occurs (conversion or
database-access error)public INTERVALDS getINTERVALDS(int parameterIndex) throws java.sql.SQLException
oracle.sql.INTERVALDS
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
oracle.sql.INTERVALDS
java.sql.SQLException
- if an error occurs (conversion or
database-access error)public TIMESTAMP getTIMESTAMP(int paramIdx) throws java.sql.SQLException
oracle.sql.TIMESTAMP
object.
paramIdx
- the first parameter is 1, the second is 2, and so on
oracle.sql.TIMESTAMP
java.sql.SQLException
- if an error occurs (conversion or database-access error)public TIMESTAMPTZ getTIMESTAMPTZ(int paramIdx) throws java.sql.SQLException
oracle.sql.TIMESTAMPTZ
object.
paramIdx
- the first parameter is 1, the second is 2, and so on
oracle.sql.TIMESTAMPTZ
java.sql.SQLException
- if an error occurs (conversion or database-access error)public TIMESTAMPLTZ getTIMESTAMPLTZ(int paramIdx) throws java.sql.SQLException
oracle.sql.TIMESTAMPLTZ
object.
paramIdx
- the first parameter is 1, the second is 2, and so on
oracle.sql.TIMESTAMPLTZ
java.sql.SQLException
- if an error occurs (conversion or database-access error)public java.io.InputStream getUnicodeStream(int parameterIndex) throws java.sql.SQLException
java.io.InputStream
object.
parameterIndex
- the first parameter is 1, the second is 2, and so on
java.io.InputStream
java.sql.SQLException
- if an error occurs (conversion or database-access error)public void registerOutParameter(int paramIndex, int sqlType, int scale, int maxLength) throws java.sql.SQLException
paramIndex
- parameter index (the first parameter is 1).sqlType
- type of the bind parameterscale
- not usedmaxLength
- maximum length of the column, specified in bytes or characters.
java.sql.SQLException
- if an error occurs (conversion or database-access
error)public void registerOutParameterBytes(int paramIndex, int sqlType, int scale, int maxLength) throws java.sql.SQLException
paramIndex
- parameter index (the first parameter is 1).sqlType
- type of the bind parameterscale
- not usedmaxLength
- maximum length of the column, specified in bytes. If not
specified, maximum length allowed for that type is used.
java.sql.SQLException
- if an error occurs (conversion or database-access
error)public void registerOutParameterChars(int paramIndex, int sqlType, int scale, int maxLength) throws java.sql.SQLException
paramIndex
- parameter index (the first parameter is 1).sqlType
- type of the bind parameterscale
- not usedmaxLength
- maximum length of the column, specified in characters. If not
specified, maximum length allowed for that type is used.
java.sql.SQLException
- if an error occurs (conversion or database-access
error)public int sendBatch() throws java.sql.SQLException
Oracle-style batching is not supported for a callable statement. This method simply returns the number of valid rows.
sendBatch
in interface OraclePreparedStatement
java.sql.SQLException
- if an error occurs (conversion or database-access error)public void setExecuteBatch(int nrows) throws java.sql.SQLException
Oracle-style batching is not supported for a callable statement. This method always sets the batch value to 1.
setExecuteBatch
in interface OraclePreparedStatement
nrows
- batch value to be set. It must be greater than or
equal to 1.
java.sql.SQLException
- if an error occurs (conversion or database-access error)getExecuteBatch
,
OracleConnection.setDefaultExecuteBatch
public java.lang.Object getPlsqlIndexTable(int paramIndex) throws java.sql.SQLException
paramIndex
- the first parameter is 1, the second is 2, and so on
java.sql.SQLException
- if a database-access error occurs.
java.sql.SQLException
- if an error occurs (conversion or database-access error)public java.lang.Object getPlsqlIndexTable(int paramIndex, java.lang.Class primitiveType) throws java.sql.SQLException
paramIndex
- the first parameter is 1, the second is 2, and so onprimitiveType
- is a primitive type class.
For example,java.lang.Double.Type
java.sql.SQLException
- if a database-access error occurs.
java.sql.SQLException
- if an error occurs (conversion or database-access error)public Datum[] getOraclePlsqlIndexTable(int paramIndex) throws java.sql.SQLException
paramIndex
- the first parameter is 1, the second is 2, and so on
java.sql.SQLException
- if a database-access error occurs.
java.sql.SQLException
- if an error occurs (conversion or database-access error)public void registerIndexTableOutParameter(int paramIndex, int maxLen, int elemSqlType, int elemMaxLen) throws java.sql.SQLException
paramIndex
- the first parameter is 1, the second is 2, and so onmaxLen
- the maximum possible number of elements.elemSqlType
- index table element SQL type (as
defined in java.sql.Types or
OracleTypes).elemMaxLen
- maximum length of the element. If not specified,
maximum length allowed for
that type is used.
java.sql.SQLException
- if sqlType is invalid, or an error occurred.public void setBinaryFloat(java.lang.String parameterName, BINARY_FLOAT x) throws java.sql.SQLException
oracle.sql.BINARY_FLOAT
value.
parameterName
- the name of the parameterx
- the parameter value
java.sql.SQLException
- if a database access error occursCallableStatement.getFloat(int)
public void setBinaryDouble(java.lang.String parameterName, BINARY_DOUBLE x) throws java.sql.SQLException
oracle.sql.BINARY_FLOAT
value.
parameterName
- the name of the parameterx
- the parameter value
java.sql.SQLException
- if a database access error occursCallableStatement.getDouble(int)
public void setStringForClob(java.lang.String parameterName, java.lang.String x) throws java.sql.SQLException
String
value.
The driver converts this
to an SQL VARCHAR
or LONGVARCHAR
value
(depending on the argument's
size relative to the driver's limits on VARCHAR
values)
when it sends it to the database. If the string is larger than
32765 it is converted to a temporary clob and that is sent
to the database.
This clob conversion produces data truncation for columns of type
VARCHAR
and LONGVARCHAR
.
parameterName
- the name of the parameterx
- the parameter value
java.sql.SQLException
- if a database access error occursCallableStatement.getString(int)
public void registerOutParameter(java.lang.String parameterName, int sqlType, int scale, int maxLength) throws java.sql.SQLException
parameterName
- the name of the parametersqlType
- SQL type code defined by java.sql.Types
.scale
- the desired number of digits to the right of the
decimal point. It must be greater than or equal to zero.maxLength
- maximum length of the column, specified in bytes or characters.
java.sql.SQLException
- if an error occurs (conversion or database-access
error)
|
Oracle10g JDBC | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |