All Packages Class Hierarchy This Package Previous Next Index
Class com.ibm.as400.access.AS400JDBCPreparedStatement
java.lang.Object
|
+----com.ibm.as400.access.AS400JDBCStatement
|
+----com.ibm.as400.access.AS400JDBCPreparedStatement
- public class AS400JDBCPreparedStatement
- extends AS400JDBCStatement
- implements PreparedStatement
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.
-
addBatch()
- Adds the set of parameters to the current batch.
-
addBatch(String)
- Adds an SQL statement to the current batch of SQL statements.
-
clearParameters()
- Releases the resources used by the current input parameter
values.
-
close()
- Releases the prepared statement's resources immediately instead of
waiting for them to be automatically released.
-
execute()
- Runs an SQL statement that may return multiple result sets.
-
execute(String)
- Runs an SQL statement that may return multiple
result sets.
-
executeBatch()
- Runs the batch of SQL statements.
-
executeQuery()
- Runs the SQL statement that returns a single
result set.
-
executeQuery(String)
- Runs an SQL statement that returns a single
result set.
-
executeUpdate()
- Runs an SQL INSERT, UPDATE, or DELETE statement, or any
SQL statement that does not return a result set.
-
executeUpdate(String)
- Runs an SQL INSERT, UPDATE, or DELETE statement, or any
SQL statement that does not return a result set.
-
getMetaData()
- Returns the ResultSetMetaData object that describes the
result set's columns.
-
setArray(int, Array)
- Sets an input parameter to an Array value.
-
setAsciiStream(int, InputStream, int)
- Sets an input parameter to an ASCII stream value.
-
setBigDecimal(int, BigDecimal)
- Sets an input parameter to a BigDecimal value.
-
setBinaryStream(int, InputStream, int)
- Sets an input parameter to a binary stream value.
-
setBlob(int, Blob)
- Sets an input parameter to a Blob value.
-
setBoolean(int, boolean)
- Sets an input parameter to a Java boolean value.
-
setByte(int, byte)
- Sets an input parameter to a Java byte value.
-
setBytes(int, byte[])
- Sets an input parameter to a Java byte array value.
-
setCharacterStream(int, Reader, int)
- Sets an input parameter to a character stream value.
-
setClob(int, Clob)
- Sets an input parameter to a Clob value.
-
setDate(int, Date)
- Sets an input parameter to a java.sql.Date value using the
default calendar.
-
setDate(int, Date, Calendar)
- Sets an input parameter to a java.sql.Date value using a
calendar other than the default.
-
setDouble(int, double)
- Sets an input parameter to a Java double value.
-
setFloat(int, float)
- Sets an input parameter to a Java float value.
-
setInt(int, int)
- Sets an input parameter to a Java int value.
-
setLong(int, long)
- Sets an input parameter to a Java long value.
-
setNull(int, int)
- Sets an input parameter to SQL NULL.
-
setNull(int, int, String)
- Sets an input parameter to SQL NULL.
-
setObject(int, Object)
- Sets an input parameter to an Object value.
-
setObject(int, Object, int)
- Sets an input parameter to an Object value.
-
setObject(int, Object, int, int)
- Sets an input parameter to an Object value.
-
setRef(int, Ref)
- Sets an input parameter to a Ref value.
-
setShort(int, short)
- Sets an input parameter to a Java short value.
-
setString(int, String)
- Sets an input parameter to a String value.
-
setTime(int, Time)
- Sets an input parameter to a java.sql.Time value using the
default calendar.
-
setTime(int, Time, Calendar)
- Sets an input parameter to a java.sql.Time value using a calendar
other than the default.
-
setTimestamp(int, Timestamp)
- Sets an input parameter to a java.sql.Timestamp value using the
default calendar.
-
setTimestamp(int, Timestamp, Calendar)
- Sets an input parameter to a java.sql.Timestamp value using a
calendar other than the default.
-
setUnicodeStream(int, InputStream, int)
- Sets an input parameter to a Unicode stream value.
Deprecated.
addBatch
public void addBatch() throws SQLException
- Adds the set of parameters to the current batch.
- Throws: SQLException
- If the statement is not open or
an input parameter has not been set.
addBatch
public void addBatch(String sql) throws SQLException
- Adds an SQL statement to the current batch of SQL statements.
Do not use this form of addBatch() on a prepared statement.
- Parameters:
- sql - The SQL statement to be added to the current batch.
This can be any SQL statement that does not return
a result set.
- Throws: SQLException
- This exception is always thrown.
- Overrides:
- addBatch in class AS400JDBCStatement
clearParameters
public void clearParameters() throws SQLException
- Releases the resources used by the current input parameter
values. In general, input
arameter values remain in effect
for repeated executions of the prepared statement. Setting an
input parameter value to a new value automatically clears its
previous value.
- Throws: SQLException
- If the statement is not open.
close
public void close() throws SQLException
- Releases the prepared statement's resources immediately instead of
waiting for them to be automatically released. This closes the
current result set.
- Throws: SQLException
- If an error occurs.
- Overrides:
- close in class AS400JDBCStatement
execute
public boolean execute() throws SQLException
- Runs an SQL statement that may return multiple result sets.
This closes the current result set and clears warnings
before executing the SQL statement again.
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.
- Returns:
- true if a result set was returned; false
if an update count was returned or nothing
was returned.
- Throws: SQLException
- If the statement is not open,
the query timeout limit is
exceeded, or an error occurs.
execute
public boolean execute(String sql) throws SQLException
- Runs an SQL statement that may return multiple
result sets. This closes the current result set
and clears warnings before executing a new SQL statement.
Do not use this form of execute() on a prepared statement.
- Parameters:
- sql - The SQL statement.
- Returns:
- true if a result set was returned, false
if an update count was returned or nothing
was returned.
- Throws: SQLException
- This exception is always thrown.
- Overrides:
- execute in class AS400JDBCStatement
executeBatch
public int[] executeBatch() throws SQLException
- Runs the batch of SQL statements. Batch updates can be used
to submit a set of SQL statements together as a single unit.
The SQL statements are run in the order in which they were
added to the batch. The batch is cleared after the SQL statements
are run. In addition, this closes the current result set and
clears warnings before executing the new SQL statement.
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.
- Returns:
- An array of row counts for the SQL statements that are run.
The array contains one element for each statement in the
batch of SQL statements. The array is ordered according to
the order in which the SQL statements were added to the batch.
- Throws: 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.
- Overrides:
- executeBatch in class AS400JDBCStatement
executeQuery
public ResultSet executeQuery() throws SQLException
- Runs the SQL statement that returns a single
result set. This closes the current result set and
clears warnings before executing the SQL statement again.
- Returns:
- The result set that contains the data produced
by the query.
- Throws: 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.
executeQuery
public ResultSet executeQuery(String sql) throws SQLException
- Runs an SQL statement that returns a single
result set. This closes the current result set
and clears warnings before executing a new SQL statement.
Do not use this form of executeQuery() on a prepared statement.
- Parameters:
- sql - The SQL statement.
- Returns:
- The result set that contains the data produced
by the query.
- Throws: SQLException
- This exception is always thrown.
- Overrides:
- executeQuery in class AS400JDBCStatement
executeUpdate
public int executeUpdate() throws SQLException
- Runs an SQL INSERT, UPDATE, or DELETE statement, or any
SQL statement that does not return a result set.
This closes the current result set and clears warnings
before executing the SQL statement again.
- Returns:
- Either the row count for INSERT, UPDATE, or
DELETE, or 0 for SQL statements that
return nothing.
- Throws: 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.
executeUpdate
public int executeUpdate(String sql) throws SQLException
- Runs an SQL INSERT, UPDATE, or DELETE statement, or any
SQL statement that does not return a result set.
This closes the current result set and clears warnings
before executing a new SQL statement.
Do not use this form of executeUpdate() on a prepared statement.
- Parameters:
- sql - The SQL statement.
- Returns:
- Either the row count for INSERT, UPDATE, or
DELETE, or 0 for SQL statements that
return nothing.
- Throws: SQLException
- This exception is always thrown.
- Overrides:
- executeUpdate in class AS400JDBCStatement
getMetaData
public ResultSetMetaData getMetaData() throws SQLException
- Returns the ResultSetMetaData object that describes the
result set's columns.
- Returns:
- The metadata object.
- Throws: SQLException
- If the statement is not open.
setArray
public void setArray(int parameterIndex,
Array parameterValue) throws SQLException
- Sets an input parameter to an Array value. DB2 for
OS/400 does not support arrays.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value.
- Throws: SQLException
- Always thrown because DB2
for OS/400 does not support arrays.
setAsciiStream
public void setAsciiStream(int parameterIndex,
InputStream parameterValue,
int length) throws SQLException
- Sets an input parameter to an ASCII stream value. The driver
reads the data from the stream as needed until no more bytes
are available. The driver converts this to an SQL VARCHAR
value.
- Parameters:
- 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.
- Throws: 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
setBigDecimal
public void setBigDecimal(int parameterIndex,
BigDecimal parameterValue) throws SQLException
- Sets an input parameter to a BigDecimal value. The driver converts
this to an SQL NUMERIC value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.
setBinaryStream
public void setBinaryStream(int parameterIndex,
InputStream parameterValue,
int length) throws SQLException
- Sets an input parameter to a binary stream value. The driver
reads the data from the stream as needed until no more bytes
are available. The driver converts this to an SQL VARBINARY
value.
- Parameters:
- 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.
- Throws: 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.
setBlob
public void setBlob(int parameterIndex,
Blob parameterValue) throws SQLException
- Sets an input parameter to a Blob value. The driver
converts this to an SQL BLOB value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or
the parameter is not an input parameter.
setBoolean
public void setBoolean(int parameterIndex,
boolean parameterValue) throws SQLException
- Sets an input parameter to a Java boolean value. The driver
converts this to an SQL SMALLINT value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or
the parameter is not an input parameter.
setByte
public void setByte(int parameterIndex,
byte parameterValue) throws SQLException
- Sets an input parameter to a Java byte value. The driver
converts this to an SQL SMALLINT value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or
the parameter is not an input parameter.
setBytes
public void setBytes(int parameterIndex,
byte parameterValue[]) throws SQLException
- Sets an input parameter to a Java byte array value. The driver
converts this to an SQL VARBINARY value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.
setCharacterStream
public void setCharacterStream(int parameterIndex,
Reader parameterValue,
int length) throws SQLException
- Sets an input parameter to a character stream value. The driver
reads the data from the character stream as needed until no more
characters are available. The driver converts this to an SQL
VARCHAR value.
- Parameters:
- 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.
- Throws: 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 stream
setClob
public void setClob(int parameterIndex,
Clob parameterValue) throws SQLException
- Sets an input parameter to a Clob value. The driver
converts this to an SQL CLOB value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or
the parameter is not an input parameter.
setDate
public void setDate(int parameterIndex,
Date parameterValue) throws SQLException
- Sets an input parameter to a java.sql.Date value using the
default calendar. The driver converts this to an SQL DATE
value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.
setDate
public void setDate(int parameterIndex,
Date parameterValue,
Calendar calendar) throws SQLException
- Sets an input parameter to a java.sql.Date value using a
calendar other than the default. The driver converts this
to an SQL DATE value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- calendar - The calendar.
- Throws: SQLException
- If the statement is not open,
the index is not valid, the parameter
is not an input parameter,
or the calendar is null.
setDouble
public void setDouble(int parameterIndex,
double parameterValue) throws SQLException
- Sets an input parameter to a Java double value. The driver
converts this to an SQL DOUBLE value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value.
- Throws: SQLException
- If the statement is not open,
the index is not valid or
the parameter is not an input parameter.
setFloat
public void setFloat(int parameterIndex,
float parameterValue) throws SQLException
- Sets an input parameter to a Java float value. The driver
converts this to an SQL REAL value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or
the parameter is not an input parameter.
setInt
public void setInt(int parameterIndex,
int parameterValue) throws SQLException
- Sets an input parameter to a Java int value. The driver
converts this to an SQL INTEGER value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value.
- Throws: SQLException
- If the statement is not open,
the index is not valid or
the parameter is not an input parameter.
setLong
public void setLong(int parameterIndex,
long parameterValue) throws SQLException
- Sets an input parameter to a Java long value. The driver
converts this to an SQL INTEGER value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or
the parameter is not an input parameter.
setNull
public void setNull(int parameterIndex,
int sqlType) throws SQLException
- Sets an input parameter to SQL NULL.
- Parameters:
- parameterIndex - The parameter index (1-based).
- sqlType - The SQL type code defined in java.sql.Types.
- Throws: 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.
setNull
public void setNull(int parameterIndex,
int sqlType,
String typeName) throws SQLException
- Sets an input parameter to SQL NULL.
- Parameters:
- 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.
- Throws: 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.
setObject
public void setObject(int parameterIndex,
Object parameterValue) throws SQLException
- Sets an input parameter to an Object value. The driver converts
this to a value of an SQL type, depending on the type of the
specified value. The JDBC specification defines a standard
mapping from Java types to SQL types. In the cases where a
SQL type is not supported by DB2 for OS/400, the
next closest matching type
is used.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- Throws: SQLException
- If the statement is not open,
the index is not valid,
the parameter is not an input parameter,
or the type of value is not supported.
setObject
public void setObject(int parameterIndex,
Object parameterValue,
int sqlType) throws SQLException
- Sets an input parameter to an Object value. The driver converts
this to a value with the specified SQL type.
- Parameters:
- 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.
- Throws: 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.
setObject
public void setObject(int parameterIndex,
Object parameterValue,
int sqlType,
int scale) throws SQLException
- Sets an input parameter to an Object value. The driver converts
this to a value with the specified SQL type.
- Parameters:
- 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.
- Throws: 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 scale is not valid.
setRef
public void setRef(int parameterIndex,
Ref parameterValue) throws SQLException
- Sets an input parameter to a Ref value. DB2 for
OS/400 does not support structured types.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value.
- Throws: SQLException
- Always thrown because DB2
for OS/400 does not support structured types.
setShort
public void setShort(int parameterIndex,
short parameterValue) throws SQLException
- Sets an input parameter to a Java short value. The driver
converts this to an SQL SMALLINT value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value.
- Throws: SQLException
- If the statement is not open,
the index is not valid or
the parameter is not an input parameter.
setString
public void setString(int parameterIndex,
String parameterValue) throws SQLException
- Sets an input parameter to a String value. The driver
converts this to an SQL VARCHAR value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.
setTime
public void setTime(int parameterIndex,
Time parameterValue) throws SQLException
- Sets an input parameter to a java.sql.Time value using the
default calendar. The driver converts this to an SQL TIME value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.
setTime
public void setTime(int parameterIndex,
Time parameterValue,
Calendar calendar) throws SQLException
- Sets an input parameter to a java.sql.Time value using a calendar
other than the default. The driver converts this to an SQL TIME
value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- calendar - The calendar.
- Throws: SQLException
- If the statement is not open,
the index is not valid, the parameter
is not an input parameter,
or the calendar is null.
setTimestamp
public void setTimestamp(int parameterIndex,
Timestamp parameterValue) throws SQLException
- Sets an input parameter to a java.sql.Timestamp value using the
default calendar. The driver converts this to an SQL TIMESTAMP
value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- Throws: SQLException
- If the statement is not open,
the index is not valid, or the parameter
is not an input parameter.
setTimestamp
public void setTimestamp(int parameterIndex,
Timestamp parameterValue,
Calendar calendar) throws SQLException
- Sets an input parameter to a java.sql.Timestamp value using a
calendar other than the default. The driver converts this to
an SQL TIMESTAMP value.
- Parameters:
- parameterIndex - The parameter index (1-based).
- parameterValue - The parameter value or null to set
the value to SQL NULL.
- calendar - The calendar.
- Throws: SQLException
- If the statement is not open,
the index is not valid, the parameter
is not an input parameter,
or the calendar is null.
setUnicodeStream
public void setUnicodeStream(int parameterIndex,
InputStream parameterValue,
int length) throws SQLException
- Note: setUnicodeStream() is deprecated.
Use setCharacterStream(int, Reader, int) instead.
- Sets an input parameter to a Unicode stream value. The driver
reads the data from the stream as needed until no more bytes
are available. The driver converts this to an SQL VARCHAR
value.
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.
- Parameters:
- 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.
- Throws: 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 stream
- See Also:
- setCharacterStream
All Packages Class Hierarchy This Package Previous Next Index