|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ibm.as400.access.AS400JDBCStatement | +--com.ibm.as400.access.AS400JDBCPreparedStatement
The AS400JDBCPreparedStatement class precompiles and stores an SQL statement. This provides the ability to efficiently run the statement multiple times. In addition, the statement may contain parameters. Use Connection.prepareStatement() to create new PreparedStatement objects.
When setting input parameter values, the caller must specify types that are compatible with the defined SQL type of the input parameter. For example, if the input parameter has SQL type INTEGER, then the caller must call setInt() to set the IN parameter value. If arbitrary type conversions are required, then use setObject() with a target SQL type.
Method Summary | |
void |
addBatch()
Adds the set of parameters to the current batch. |
void |
addBatch(java.lang.String sql)
Adds an SQL statement to the current batch of SQL statements. |
void |
clearParameters()
Releases the resources used by the current input parameter values. |
void |
close()
Releases the prepared statement's resources immediately instead of waiting for them to be automatically released. |
boolean |
execute()
Runs an SQL statement that may return multiple result sets. |
boolean |
execute(java.lang.String sql)
Runs an SQL statement that may return multiple result sets. |
boolean |
execute(java.lang.String sql,
int autoGeneratedKeys)
Runs an SQL statement that may return multiple result sets and makes any auto-generated keys available for retrieval using Statement.getGeneratedKeys(). |
int[] |
executeBatch()
Runs the batch of SQL statements. |
java.sql.ResultSet |
executeQuery()
Runs the SQL statement that returns a single result set. |
java.sql.ResultSet |
executeQuery(java.lang.String sql)
Runs an SQL statement that returns a single result set. |
int |
executeUpdate()
Runs an SQL INSERT, UPDATE, or DELETE statement, or any SQL statement that does not return a result set. |
int |
executeUpdate(java.lang.String sql)
Runs an SQL INSERT, UPDATE, or DELETE statement, or any SQL statement that does not return a result set. |
int |
executeUpdate(java.lang.String sql,
int autoGeneratedKeys)
Runs an SQL INSERT, UPDATE, or DELETE statement, or any SQL statement that does not return a result set and makes any auto-generated keys available for retrieval using Statement.getGeneratedKeys(). |
java.sql.ResultSetMetaData |
getMetaData()
Returns the ResultSetMetaData object that describes the result set's columns. |
java.sql.ParameterMetaData |
getParameterMetaData()
Returns the number, types, and properties of a PreparedStatement object's parameters. |
void |
setArray(int parameterIndex,
java.sql.Array parameterValue)
Sets an input parameter to an Array value. |
void |
setAsciiStream(int parameterIndex,
java.io.InputStream parameterValue,
int length)
Sets an input parameter to an ASCII stream value. |
void |
setBigDecimal(int parameterIndex,
java.math.BigDecimal parameterValue)
Sets an input parameter to a BigDecimal value. |
void |
setBinaryStream(int parameterIndex,
java.io.InputStream parameterValue,
int length)
Sets an input parameter to a binary stream value. |
void |
setBlob(int parameterIndex,
java.sql.Blob parameterValue)
Sets an input parameter to a Blob value. |
void |
setBoolean(int parameterIndex,
boolean parameterValue)
Sets an input parameter to a Java boolean value. |
void |
setByte(int parameterIndex,
byte parameterValue)
Sets an input parameter to a Java byte value. |
void |
setBytes(int parameterIndex,
byte[] parameterValue)
Sets an input parameter to a Java byte array value. |
void |
setCharacterStream(int parameterIndex,
java.io.Reader parameterValue,
int length)
Sets an input parameter to a character stream value. |
void |
setClob(int parameterIndex,
java.sql.Clob parameterValue)
Sets an input parameter to a Clob value. |
void |
setDate(int parameterIndex,
java.sql.Date parameterValue)
Sets an input parameter to a java.sql.Date value using the default calendar. |
void |
setDate(int parameterIndex,
java.sql.Date parameterValue,
java.util.Calendar calendar)
Sets an input parameter to a java.sql.Date value using a calendar other than the default. |
void |
setDouble(int parameterIndex,
double parameterValue)
Sets an input parameter to a Java double value. |
void |
setFloat(int parameterIndex,
float parameterValue)
Sets an input parameter to a Java float value. |
void |
setInt(int parameterIndex,
int parameterValue)
Sets an input parameter to a Java int value. |
void |
setLong(int parameterIndex,
long parameterValue)
Sets an input parameter to a Java long value. |
void |
setNull(int parameterIndex,
int sqlType)
Sets an input parameter to SQL NULL. |
void |
setNull(int parameterIndex,
int sqlType,
java.lang.String typeName)
Sets an input parameter to SQL NULL. |
void |
setObject(int parameterIndex,
java.lang.Object parameterValue)
Sets an input parameter to an Object value. |
void |
setObject(int parameterIndex,
java.lang.Object parameterValue,
int sqlType)
Sets an input parameter to an Object value. |
void |
setObject(int parameterIndex,
java.lang.Object parameterValue,
int sqlType,
int scale)
Sets an input parameter to an Object value. |
void |
setRef(int parameterIndex,
java.sql.Ref parameterValue)
Sets an input parameter to a Ref value. |
void |
setShort(int parameterIndex,
short parameterValue)
Sets an input parameter to a Java short value. |
void |
setString(int parameterIndex,
java.lang.String parameterValue)
Sets an input parameter to a String value. |
void |
setTime(int parameterIndex,
java.sql.Time parameterValue)
Sets an input parameter to a java.sql.Time value using the default calendar. |
void |
setTime(int parameterIndex,
java.sql.Time parameterValue,
java.util.Calendar calendar)
Sets an input parameter to a java.sql.Time value using a calendar other than the default. |
void |
setTimestamp(int parameterIndex,
java.sql.Timestamp parameterValue)
Sets an input parameter to a java.sql.Timestamp value using the default calendar. |
void |
setTimestamp(int parameterIndex,
java.sql.Timestamp parameterValue,
java.util.Calendar calendar)
Sets an input parameter to a java.sql.Timestamp value using a calendar other than the default. |
void |
setUnicodeStream(int parameterIndex,
java.io.InputStream parameterValue,
int length)
Deprecated. Use setCharacterStream(int, Reader, int) instead. |
void |
setURL(int parameterIndex,
java.net.URL parameterValue)
Sets an input parameter to a URL value. |
Methods inherited from class com.ibm.as400.access.AS400JDBCStatement |
cancel, clearBatch, clearWarnings, execute, execute, executeUpdate, executeUpdate, finalize, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setQueryTimeout, toString |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.sql.Statement |
cancel, clearBatch, clearWarnings, getConnection, getFetchDirection, getFetchSize, getMaxFieldSize, getMaxRows, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetType, getUpdateCount, getWarnings, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setQueryTimeout |
Method Detail |
public void addBatch() throws java.sql.SQLException
addBatch
in interface java.sql.PreparedStatement
java.sql.SQLException
- If the statement is not open or
an input parameter has not been set.public void addBatch(java.lang.String sql) throws java.sql.SQLException
Do not use this form of addBatch() on a prepared statement.
addBatch
in interface java.sql.Statement
addBatch
in class AS400JDBCStatement
sql
- The SQL statement to be added to the current batch.
This can be any SQL statement that does not return
a result set.java.sql.SQLException
- This exception is always thrown.public void clearParameters() throws java.sql.SQLException
clearParameters
in interface java.sql.PreparedStatement
java.sql.SQLException
- If the statement is not open.public void close() throws java.sql.SQLException
close
in interface java.sql.Statement
close
in class AS400JDBCStatement
java.sql.SQLException
- If an error occurs.public boolean execute() throws java.sql.SQLException
Under some situations, a single SQL statement may return multiple result sets, an update count, or both. This might occur either when executing a stored procedure that returns multiple result sets or when dynamically executing an unknown SQL string.
Use Statement.getMoreResults(), Statement.getResultSet(), and Statement.getUpdateCount() to navigate through multiple result sets, an update count, or both.
execute
in interface java.sql.PreparedStatement
java.sql.SQLException
- If the statement is not open,
the query timeout limit is
exceeded, or an error occurs.public boolean execute(java.lang.String sql) throws java.sql.SQLException
Do not use this form of execute() on a prepared statement.
execute
in interface java.sql.Statement
execute
in class AS400JDBCStatement
sql
- The SQL statement.java.sql.SQLException
- This exception is always thrown.public boolean execute(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
Do not use this form of execute() on a prepared statement.
execute
in class AS400JDBCStatement
sql
- The SQL statement.autoGeneratedKeys
- Indicates whether auto-generated keys should be made available for
retrieval. Valid values are Statement.RETURN_GENERATED_KEYS and
Statement.NO_GENERATED_KEYS.java.sql.SQLException
- This exception is always thrown.public int[] executeBatch() throws java.sql.SQLException
When batch updates are run, autocommit should usually be turned off. This allows the caller to decide whether or not to commit the transaction in the event that an error occurs and some of the SQL statements in a batch fail to run.
executeBatch
in interface java.sql.Statement
executeBatch
in class AS400JDBCStatement
java.sql.SQLException
- If the statement is not open,
an SQL statement contains a syntax
error, the query timeout limit is
exceeded, an SQL statement returns
a result set, or an error occurs.public java.sql.ResultSet executeQuery() throws java.sql.SQLException
executeQuery
in interface java.sql.PreparedStatement
java.sql.SQLException
- If the statement is not open, no
result set is returned by the database,
the query timeout limit is exceeded,
an input parameter has not been set,
or an error occurs.public java.sql.ResultSet executeQuery(java.lang.String sql) throws java.sql.SQLException
Do not use this form of executeQuery() on a prepared statement.
executeQuery
in interface java.sql.Statement
executeQuery
in class AS400JDBCStatement
sql
- The SQL statement.java.sql.SQLException
- This exception is always thrown.public int executeUpdate() throws java.sql.SQLException
executeUpdate
in interface java.sql.PreparedStatement
java.sql.SQLException
- If the statement is not open,
the query timeout limit is
exceeded, the statement returns
a result set, an input parameter
has not been set, or an error occurs.public int executeUpdate(java.lang.String sql) throws java.sql.SQLException
Do not use this form of executeUpdate() on a prepared statement.
executeUpdate
in interface java.sql.Statement
executeUpdate
in class AS400JDBCStatement
sql
- The SQL statement.java.sql.SQLException
- This exception is always thrown.public int executeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
Do not use this form of executeUpdate() on a prepared statement.
executeUpdate
in class AS400JDBCStatement
sql
- The SQL statement.java.sql.SQLException
- This exception is always thrown.public java.sql.ResultSetMetaData getMetaData() throws java.sql.SQLException
getMetaData
in interface java.sql.PreparedStatement
java.sql.SQLException
- If the statement is not open.public java.sql.ParameterMetaData getParameterMetaData() throws java.sql.SQLException
java.sql.SQLException
- If the statement is not open.public void setArray(int parameterIndex, java.sql.Array parameterValue) throws java.sql.SQLException
setArray
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value.java.sql.SQLException
- Always thrown because DB2
UDB for iSeries does not support arrays.public void setAsciiStream(int parameterIndex, java.io.InputStream parameterValue, int length) throws java.sql.SQLException
setAsciiStream
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.length
- The number of bytes in the stream.java.sql.SQLException
- If the statement is not open,
the index is not valid, the parameter
is not an input parameter,
the length is not valid,
the input stream does not contain all
ASCII characters, or an error occurs
while reading the input stream.public void setBigDecimal(int parameterIndex, java.math.BigDecimal parameterValue) throws java.sql.SQLException
setBigDecimal
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.java.sql.SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.public void setBinaryStream(int parameterIndex, java.io.InputStream parameterValue, int length) throws java.sql.SQLException
setBinaryStream
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.length
- The number of bytes in the stream.java.sql.SQLException
- If the statement is not open,
the index is not valid, the parameter
is not an input parameter,
the length is not valid, or
an error occurs while reading the
input stream.public void setBlob(int parameterIndex, java.sql.Blob parameterValue) throws java.sql.SQLException
setBlob
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.java.sql.SQLException
- If the statement is not open,
the index is not valid,
the parameter is not an input parameter,
or the parameter is not serializable
(when proxy support is in use).public void setBoolean(int parameterIndex, boolean parameterValue) throws java.sql.SQLException
setBoolean
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value.java.sql.SQLException
- If the statement is not open,
the index is not valid, or
the parameter is not an input parameter.public void setByte(int parameterIndex, byte parameterValue) throws java.sql.SQLException
setByte
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value.java.sql.SQLException
- If the statement is not open,
the index is not valid, or
the parameter is not an input parameter.public void setBytes(int parameterIndex, byte[] parameterValue) throws java.sql.SQLException
setBytes
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.java.sql.SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.public void setCharacterStream(int parameterIndex, java.io.Reader parameterValue, int length) throws java.sql.SQLException
setCharacterStream
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.length
- The number of bytes in the reader.java.sql.SQLException
- If the statement is not open,
the index is not valid, the parameter
is not an input parameter,
the length is not valid,
or an error occurs while reading the
character streampublic void setClob(int parameterIndex, java.sql.Clob parameterValue) throws java.sql.SQLException
setClob
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.java.sql.SQLException
- If the statement is not open,
the index is not valid,
the parameter is not an input parameter,
or the parameter is not serializable
(when proxy support is in use).public void setDate(int parameterIndex, java.sql.Date parameterValue) throws java.sql.SQLException
setDate
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.java.sql.SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.public void setDate(int parameterIndex, java.sql.Date parameterValue, java.util.Calendar calendar) throws java.sql.SQLException
setDate
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.calendar
- The calendar.java.sql.SQLException
- If the statement is not open,
the index is not valid, the parameter
is not an input parameter,
or the calendar is null.public void setDouble(int parameterIndex, double parameterValue) throws java.sql.SQLException
setDouble
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value.java.sql.SQLException
- If the statement is not open,
the index is not valid or
the parameter is not an input parameter.public void setFloat(int parameterIndex, float parameterValue) throws java.sql.SQLException
setFloat
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value.java.sql.SQLException
- If the statement is not open,
the index is not valid, or
the parameter is not an input parameter.public void setInt(int parameterIndex, int parameterValue) throws java.sql.SQLException
setInt
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value.java.sql.SQLException
- If the statement is not open,
the index is not valid or
the parameter is not an input parameter.public void setLong(int parameterIndex, long parameterValue) throws java.sql.SQLException
setLong
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value.java.sql.SQLException
- If the statement is not open,
the index is not valid, or
the parameter is not an input parameter.public void setNull(int parameterIndex, int sqlType) throws java.sql.SQLException
setNull
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).sqlType
- The SQL type code defined in java.sql.Types.java.sql.SQLException
- If the statement is not open,
the index is not valid,
the parameter is not an input parameter,
or the SQL type is not valid.public void setNull(int parameterIndex, int sqlType, java.lang.String typeName) throws java.sql.SQLException
setNull
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).sqlType
- The SQL type code defined in java.sql.Types.typeName
- The fully-qualified name of an SQL structured type. This value will be ignored.java.sql.SQLException
- If the statement is not open,
the index is not valid,
the parameter is not an input parameter,
or the SQL type is not valid.public void setObject(int parameterIndex, java.lang.Object parameterValue) throws java.sql.SQLException
setObject
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.java.sql.SQLException
- If the statement is not open,
the index is not valid,
the parameter is not an input parameter,
the type of value is not supported,
or the parameter is not serializable
(when proxy support is in use).public void setObject(int parameterIndex, java.lang.Object parameterValue, int sqlType) throws java.sql.SQLException
setObject
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.sqlType
- The SQL type code defined in java.sql.Types.java.sql.SQLException
- If the statement is not open,
the index is not valid,
the parameter is not an input parameter,
the SQL type is not valid,
or the parameter is not serializable
(when proxy support is in use).public void setObject(int parameterIndex, java.lang.Object parameterValue, int sqlType, int scale) throws java.sql.SQLException
setObject
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.sqlType
- The SQL type code defined in java.sql.Types.scale
- The number of digits after the decimal
if sqlType is DECIMAL or NUMERIC.java.sql.SQLException
- If the statement is not open,
the index is not valid,
the parameter is not an input parameter,
the SQL type is not valid,
the scale is not valid,
or the parameter is not serializable
(when proxy support is in use).public void setRef(int parameterIndex, java.sql.Ref parameterValue) throws java.sql.SQLException
setRef
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value.java.sql.SQLException
- Always thrown because DB2
UDB for iSeries does not support structured types.public void setShort(int parameterIndex, short parameterValue) throws java.sql.SQLException
setShort
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value.java.sql.SQLException
- If the statement is not open,
the index is not valid or
the parameter is not an input parameter.public void setString(int parameterIndex, java.lang.String parameterValue) throws java.sql.SQLException
setString
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.java.sql.SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.public void setTime(int parameterIndex, java.sql.Time parameterValue) throws java.sql.SQLException
setTime
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.java.sql.SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.public void setTime(int parameterIndex, java.sql.Time parameterValue, java.util.Calendar calendar) throws java.sql.SQLException
setTime
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.calendar
- The calendar.java.sql.SQLException
- If the statement is not open,
the index is not valid, the parameter
is not an input parameter,
or the calendar is null.public void setTimestamp(int parameterIndex, java.sql.Timestamp parameterValue) throws java.sql.SQLException
setTimestamp
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.java.sql.SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.public void setTimestamp(int parameterIndex, java.sql.Timestamp parameterValue, java.util.Calendar calendar) throws java.sql.SQLException
setTimestamp
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.calendar
- The calendar.java.sql.SQLException
- If the statement is not open,
the index is not valid, the parameter
is not an input parameter,
or the calendar is null.public void setUnicodeStream(int parameterIndex, java.io.InputStream parameterValue, int length) throws java.sql.SQLException
Note that the number of bytes in a Unicode stream can be computed as 2 multiplied by the number of characters plus 2 bytes for the byte-order mark. If an uneven number of bytes is specified, then Java will convert this to an empty String.
setUnicodeStream
in interface java.sql.PreparedStatement
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.length
- The number of bytes in the stream.java.sql.SQLException
- If the statement is not open,
the index is not valid, the parameter
is not an input parameter, the length
is not valid,
the input stream does not contain all
Unicode characters, or an error occurs
while reading the input streamsetCharacterStream(int, java.io.Reader, int)
public void setURL(int parameterIndex, java.net.URL parameterValue) throws java.sql.SQLException
parameterIndex
- The parameter index (1-based).parameterValue
- The parameter value or null to set
the value to SQL NULL.java.sql.SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |