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 a SQL statement. This provides the ability to efficiently execute the statement multiple times. In addition, the statement may contain parameters. Use AS400JDBCConnection.prepareStatement() to create new AS400JDBCPreparedStatement 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.

Some of the set methods convert parameter values to different types than are described in the JDBC specification. This is because some SQL types are not supported by DB2 for OS/400. See Unsupported SQL Types for a complete list.

See Also:
AS400JDBCResultSet

Method Index

 o clearParameters()
Releases the resources used by the current input parameter values.
 o close()
Releases the prepared statement's resources immediately instead of waiting for them to be automatically released.
 o execute()
Runs a SQL statement that may return multiple result sets.
 o execute(String)
Runs a SQL statement that may return multiple result sets.
 o executeQuery()
Runs the SQL statement that returns a single result set.
 o executeQuery(String)
Runs a SQL statement that returns a single result set.
 o executeUpdate()
Runs a SQL INSERT, UPDATE, or DELETE statement, or any SQL statement that does not necessarily return a result set.
 o executeUpdate(String)
Runs a SQL INSERT, UPDATE, or DELETE statement, or any SQL statement that does not necessarily return a result set.
 o setAsciiStream(int, InputStream, int)
Sets an input parameter to an ASCII stream value.
 o setBigDecimal(int, BigDecimal)
Sets an input parameter to a BigDecimal value.
 o setBinaryStream(int, InputStream, int)
Sets an input parameter to a binary stream value.
 o setBoolean(int, boolean)
Sets an input parameter to a Java boolean value.
 o setByte(int, byte)
Sets an input parameter to a Java byte value.
 o setBytes(int, byte[])
Sets an input parameter to a Java byte array value.
 o setDate(int, Date)
Sets an input parameter to a java.sql.Date value.
 o setDouble(int, double)
Sets an input parameter to a Java double value.
 o setFloat(int, float)
Sets an input parameter to a Java float value.
 o setInt(int, int)
Sets an input parameter to a Java int value.
 o setLong(int, long)
Sets an input parameter to a Java long value.
 o setNull(int, int)
Sets an input parameter to SQL NULL.
 o setObject(int, Object)
Sets an input parameter to an Object value.
 o setObject(int, Object, int)
Sets an input parameter to an Object value.
 o setObject(int, Object, int, int)
Sets an input parameter to an Object value.
 o setShort(int, short)
Sets an input parameter to a Java short value.
 o setString(int, String)
Sets an input parameter to a String value.
 o setTime(int, Time)
Sets an input parameter to a java.sql.Time value.
 o setTimestamp(int, Timestamp)
Sets an input parameter to a java.sql.Timestamp value.
 o setUnicodeStream(int, InputStream, int)
Sets an input parameter to a Unicode stream value.

Methods

 o clearParameters
 public void clearParameters() throws SQLException
Releases the resources used by the current input parameter values. In general, input parameter 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.
 o 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
 o execute
 public boolean execute() throws SQLException
Runs a SQL statement that may return multiple result sets. This closes the current result set 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.
 o execute
 public boolean execute(String sql) throws SQLException
Runs a SQL statement that may return multiple result sets. This closes the current result set before executing a new SQL statement.

This executes a statement other than the one currently prepared.

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
If the statement is not open, the SQL statement contains a syntax error, the query timeout limit is exceeded, or an error occurs.
Overrides:
execute in class AS400JDBCStatement
 o executeQuery
 public ResultSet executeQuery() throws SQLException
Runs the SQL statement that returns a single result set. This closes the current result set 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, or an error occurs.
 o executeQuery
 public ResultSet executeQuery(String sql) throws SQLException
Runs a SQL statement that returns a single result set. This closes the current result set before executing a new SQL statement.

This executes a statement other than the one currently prepared.

Parameters:
sql - The SQL statement.
Returns:
The result set that contains the data produced by the query.
Throws: SQLException
If the statement is not open, the SQL statement contains a syntax error, no result set is returned by the database, the query timeout limit is exceeded, or an error occurs.
Overrides:
executeQuery in class AS400JDBCStatement
 o executeUpdate
 public int executeUpdate() throws SQLException
Runs a SQL INSERT, UPDATE, or DELETE statement, or any SQL statement that does not necessarily return a result set. This closes the current result set 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, or an error occurs.
 o executeUpdate
 public int executeUpdate(String sql) throws SQLException
Runs a SQL INSERT, UPDATE, or DELETE statement, or any SQL statement that does not necessarily return a result set. This closes the current result set before executing a new SQL statement.

This executes a statement other than the one currently prepared.

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
If the statement is not open, the SQL statement contains a syntax error, the query timeout limit is exceeded, or an error occurs.
Overrides:
executeUpdate in class AS400JDBCStatement
 o setAsciiStream
 public void setAsciiStream(int index,
                            InputStream value,
                            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 a SQL VARCHAR value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
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 value is null, or the length is not valid.
 o setBigDecimal
 public void setBigDecimal(int index,
                           BigDecimal value) throws SQLException
Sets an input parameter to a BigDecimal value. The driver converts this to a SQL NUMERIC value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid, the parameter is not an input parameter, or the value is null.
 o setBinaryStream
 public void setBinaryStream(int index,
                             InputStream value,
                             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 a SQL VARBINARY value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
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 value is null, or the length is not valid.
 o setBoolean
 public void setBoolean(int index,
                        boolean value) throws SQLException
Sets an input parameter to a Java boolean value. The driver converts this to a SQL SMALLINT value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid, or the parameter is not an input parameter.
 o setByte
 public void setByte(int index,
                     byte value) throws SQLException
Sets an input parameter to a Java byte value. The driver converts this to a SQL SMALLINT value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid, or the parameter is not an input parameter.
 o setBytes
 public void setBytes(int index,
                      byte value[]) throws SQLException
Sets an input parameter to a Java byte array value. The driver converts this to a SQL VARBINARY value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid, the parameter is not an input parameter, or the value is null.
 o setDate
 public void setDate(int index,
                     Date value) throws SQLException
Sets an input parameter to a java.sql.Date value. The driver converts this to a SQL DATE value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid, the parameter is not an input parameter, or the value is null.
 o setDouble
 public void setDouble(int index,
                       double value) throws SQLException
Sets an input parameter to a Java double value. The driver converts this to a SQL DOUBLE value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid or the parameter is not an input parameter.
 o setFloat
 public void setFloat(int index,
                      float value) throws SQLException
Sets an input parameter to a Java float value. The driver converts this to a SQL REAL value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid, or the parameter is not an input parameter.
 o setInt
 public void setInt(int index,
                    int value) throws SQLException
Sets an input parameter to a Java int value. The driver converts this to a SQL INTEGER value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid or the parameter is not an input parameter.
 o setLong
 public void setLong(int index,
                     long value) throws SQLException
Sets an input parameter to a Java long value. The driver converts this to a SQL INTEGER value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid, or the parameter is not an input parameter.
 o setNull
 public void setNull(int index,
                     int sqlType) throws SQLException
Sets an input parameter to SQL NULL.

Parameters:
index - 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.
 o setObject
 public void setObject(int index,
                       Object value,
                       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:
index - The parameter index (1-based).
value - The parameter value.
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 value is null, the SQL type is not valid, or the scale is not valid.
 o setObject
 public void setObject(int index,
                       Object value,
                       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:
index - The parameter index (1-based).
value - The parameter value.
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, the value is null, or the SQL type is not valid.
 o setObject
 public void setObject(int index,
                       Object value) throws SQLException
Sets an input parameter to an Object value. The driver converts this to a value of a 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:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid, the parameter is not an input parameter, the value is null, or the type of value is not supported.
 o setShort
 public void setShort(int index,
                      short value) throws SQLException
Sets an input parameter to a Java short value. The driver converts this to a SQL SMALLINT value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid or the parameter is not an input parameter.
 o setString
 public void setString(int index,
                       String value) throws SQLException
Sets an input parameter to a String value. The driver converts this to a SQL VARCHAR value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid, the parameter is not an input parameter, or the value is null.
 o setTime
 public void setTime(int index,
                     Time value) throws SQLException
Sets an input parameter to a java.sql.Time value. The driver converts this to a SQL TIME value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid, the parameter is not an input parameter, or the value is null.
 o setTimestamp
 public void setTimestamp(int index,
                          Timestamp value) throws SQLException
Sets an input parameter to a java.sql.Timestamp value. The driver converts this to a SQL TIMESTAMP value.

Parameters:
index - The parameter index (1-based).
value - The parameter value.
Throws: SQLException
If the statement is not open, the index is not valid, the parameter is not an input parameter, or the value is null.
 o setUnicodeStream
 public void setUnicodeStream(int index,
                              InputStream value,
                              int length) throws SQLException
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 a 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:
index - The parameter index (1-based).
value - The parameter value.
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 value is null, or the length is not valid.

All Packages  Class Hierarchy  This Package  Previous  Next  Index