DB2PreparedStatement interface
The com.ibm.db2.jcc.DB2PreparedStatement interface extends the com.ibm.db2.jcc.DB2Statement and java.sql.PreparedStatement interfaces.
DB2PreparedStatement fields
The following constants are defined only for the IBM® Data Server Driver for JDBC and SQLJ.
- public static DBIndicatorDefault DB_PARAMETER_DEFAULT
- This constant can be used with standard interfaces, such as PreparedStatement.setObject or ResultSet.updateObject to indicate that the default value is assigned to the associated parameter.
- public static DBIndicatorUnassigned DB_PARAMETER_UNASSIGNED
- This constant can be used with standard interfaces, such as PreparedStatement.setObject or ResultSet.updateObject to indicate that the associated parameter is unassigned.
DB2PreparedStatement methods
The following methods are defined only for the IBM Data Server Driver for JDBC and SQLJ.
- executeDB2QueryBatch
- Format:
public void executeDB2QueryBatch() throws java.sql.SQLException
Executes a statement batch that contains queries with parameters.
This method is not supported for connections to IBM Informix® data sources.
- getDBGeneratedKeys
- Format:
public java.sql.ResultSet[] getDBGeneratedKeys() throws java.sql.SQLException
Retrieves automatically generated keys that were created when INSERT statements were executed in a batch. Each ResultSet object that is returned contains the automatically generated keys for a single statement in the batch.
getDBGeneratedKeys returns an array of length 0 under the following conditions:
- getDBGeneratedKeys is called out of sequence. For example, if getDBGeneratedKeys is called before executeBatch, an array of length 0 is returned.
- The PreparedStatement that is executed in a
batch was not created using one of the following methods:
Connection.prepareStatement(String sql, int[] autoGeneratedKeys) Connection.prepareStatement(String sql, String[] autoGeneratedColumnNames) Connection.prepareStatement(String sql, Statement.RETURN_GENERATED_KEYS)
If getDBGeneratedKeys is called against a PreparedStatement that was created using one of the previously listed methods, and the PreparedStatement is not in a batch, a single ResultSet is returned.
- getEstimateCost
- Format:
public int getEstimateCost() throws java.sql.SQLException
Returns the estimated cost of an SQL statement from the data server after the data server dynamically prepares the statement successfully. This value is the same as the fourth element in the sqlerrd array of the SQLCA.
If the deferPrepares property is set to
true
, calling getEstimateCost causes the data server to execute a dynamic prepare operation.If the SQL statement cannot be prepared, or the data server does not return estimated cost information at prepare time, getEstimateCost returns -1.
- getEstimateRowCount
- Format:
public int getEstimateRowCount() throws java.sql.SQLException
Returns the estimated row count for an SQL statement from the data server after the data server dynamically prepares the statement successfully. This value is the same as the third element in the sqlerrd array of the SQLCA.
If the deferPrepares property is set to
true
, calling getEstimateRowCount causes the data server to execute a dynamic prepare operation.If the SQL statement cannot be prepared, or the data server does not return estimated row count information at prepare time, getEstimateRowCount returns -1.
- setDBTimestamp
- Format:
public void setDBTimestamp(int parameterIndex, DBTimestamp timestamp) throws java.sql.SQLException
Assigns a DBTimestamp value to a parameter.
Parameters:- parameterIndex
- The index of the parameter marker to which a DBTimestamp variable value is assigned.
- timestamp
- The DBTimestamp value that is assigned to the parameter marker.
This method is not supported for connections to IBM Informix data sources.
- setJccArrayAtName
- Format:
public void setJccArrayAtName(String parameterMarkerName, java.sql.Array x) throws java.sql.SQLException
Assigns a java.sql.Array value to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The java.sql.Array value that is assigned to the named parameter marker.
- setJccAsciiStreamAtName
- Formats:
Supported by the IBM Data Server Driver for JDBC and SQLJ version 3.57 and later:
public void setJccAsciiStreamAtName(String parameterMarkerName, java.io.InputStream x, int length) throws java.sql.SQLException
Supported by the IBM Data Server Driver for JDBC and SQLJ version 4.7 and later:
public void setJccAsciiStreamAtName(String parameterMarkerName, java.io.InputStream x) throws java.sql.SQLException public void setJccAsciiStreamAtName(String parameterMarkerName, java.io.InputStream x, long length) throws java.sql.SQLException
Assigns an ASCII value in a java.io.InputStream to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The ASCII java.io.InputStream value that is assigned to the parameter marker.
- length
- The length in bytes of the java.io.InputStream value that is assigned to the named parameter marker.
- setJccBigDecimalAtName
- Format:
public void setJccBigDecimalAtName(String parameterMarkerName, java.math.BigDecimal x) throws java.sql.SQLException
Assigns a java.math.BigDecimal value to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The java.math.BigDecimal value that is assigned to the named parameter marker.
- setJccBinaryStreamAtName
- Formats:
Supported by the IBM Data Server Driver for JDBC and SQLJ version 3.57 and later:
public void setJccBinaryStreamAtName(String parameterMarkerName, java.io.InputStream x, int length) throws java.sql.SQLException
Supported by the IBM Data Server Driver for JDBC and SQLJ version 4.7 and later:
public void setJccBinaryStreamAtName(String parameterMarkerName, java.io.InputStream x) throws java.sql.SQLException public void setJccBinaryStreamAtName(String parameterMarkerName, java.io.InputStream x, long length) throws java.sql.SQLException
Assigns a binary value in a java.io.InputStream to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The binary java.io.InputStream value that is assigned to the parameter marker.
- length
- The number of bytes of the java.io.InputStream value that are assigned to the named parameter marker.
- setJccBlobAtName
- Formats:
Supported by the IBM Data Server Driver for JDBC and SQLJ version 3.57 and later:
public void setJccBlobAtName(String parameterMarkerName, java.sql.Blob x) throws java.sql.SQLException
Supported by the IBM Data Server Driver for JDBC and SQLJ version 4.7 and later:
public void setJccBlobAtName(String parameterMarkerName, java.io.InputStream x) throws java.sql.SQLException public void setJccBlobAtName(String parameterMarkerName, java.io.InputStream x, long length) throws java.sql.SQLException
Assigns a BLOB value to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The java.sql.Blob value or java.io.InputStream value that is assigned to the parameter marker.
- length
- The number of bytes of the java.io.InputStream value that are assigned to the named parameter marker.
- setJccBooleanAtName
- Format:
public void setJccBooleanAtName(String parameterMarkerName, boolean x) throws java.sql.SQLException
Assigns a boolean value to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The boolean value that is assigned to the named parameter marker.
- setJccByteAtName
- Format:
public void setJccByteAtName(String parameterMarkerName, byte x) throws java.sql.SQLException
Assigns a byte value to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The byte value that is assigned to the named parameter marker.
- setJccBytesAtName
- Format:
public void setJccBytesAtName(String parameterMarkerName, byte[] x) throws java.sql.SQLException
Assigns an array of byte values to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The byte array that is assigned to the named parameter marker.
- setJccCharacterStreamAtName
- Formats:
Supported by the IBM Data Server Driver for JDBC and SQLJ version 3.57 and later:
public void setJccCharacterStreamAtName(String parameterMarkerName, java.io.Reader x, int length) throws java.sql.SQLException
Supported by the IBM Data Server Driver for JDBC and SQLJ version 4.7 and later:
public void setJccCharacterStreamAtName(String parameterMarkerName, java.io.Reader x) throws java.sql.SQLException public void setJccCharacterStreamAtName(String parameterMarkerName, java.io.Reader x, long length) throws java.sql.SQLException
Assigns a Unicode value in a java.io.Reader to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The Unicode java.io.Reader value that is assigned to the named parameter marker.
- length
- The number of characters of the java.io.InputStream value that are assigned to the named parameter marker.
- setJccClobAtName
- Formats:
Supported by the IBM Data Server Driver for JDBC and SQLJ version 3.57 and later:
public void setJccClobAtName(String parameterMarkerName, java.sql.Clob x) throws java.sql.SQLException
Supported by the IBM Data Server Driver for JDBC and SQLJ version 4.7 and later:
public void setJccClobAtName(String parameterMarkerName, java.io.Reader x) throws java.sql.SQLException public void setJccClobAtName(String parameterMarkerName, java.io.Reader x, long length) throws java.sql.SQLException
Assigns a CLOB value to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The java.sql.Clob value or java.io.Reader value that is assigned to the named parameter marker.
- length
- The number of bytes of the java.io.InputStream value that are assigned to the named parameter marker.
- setJccDateAtName
- Formats:
public void setJccDateAtName(String parameterMarkerName, java.sql.Date x) throws java.sql.SQLException public void setJccDateAtName(String parameterMarkerName, java.sql.Date x, java.util.Calendar cal) throws java.sql.SQLException
Assigns a java.sql.Date value to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The java.sql.Date value that is assigned to the named parameter marker.
- cal
- The java.util.Calendar object that the IBM Data Server Driver for JDBC and SQLJ uses to construct the date.
- setJccDBTimestampAtName
- Format:
public void setJccDBTimestampAtName(String parameterMarkerName, DBTimestamp timestamp) throws java.sql.SQLException
Assigns a DBTimestamp value to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a DBTimestamp variable value is assigned.
- timestamp
- The DBTimestamp value that is assigned to the named parameter marker.
This method is not supported for connections to IBM Informix data sources.
- setJccDBDefaultAtName
- Formats:
public void setJccDBDefaultAtName(String parameterMarkerName) throws SQLException
Assigns the default value to a named parameter marker. Execution of setJccDBDefaultAtName produces the same results as using the literal DEFAULT in the SQL string, instead of the parameter marker name.
Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
This method is not supported for connections to IBM Informix data sources.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1). - setJccDBUnassignedAtName
- Formats:
public void setJccDBUnassignedAtName(String parameterMarkerName) throws SQLException
Does not assign a value to the specified named parameter. Execution of setJccDBUnassignedAtName produces the same result as if the specified parameter marker name had not appeared in the SQL string.
Parameters:- parameterMarkerName
- The name of the parameter marker whose value is to be unassigned.
This method is not supported for connections to IBM Informix data sources.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1). - setJccDoubleAtName
- Format:
public void setJccDoubleAtName(String parameterMarkerName, double x) throws java.sql.SQLException
Assigns a value of type double to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The value of type double that is assigned to the parameter marker.
- setJccFloatAtName
- Format:
public void setJccFloatAtName(String parameterMarkerName, float x) throws java.sql.SQLException
Assigns a value of type float to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The value of type float that is assigned to the parameter marker.
- setJccIntAtName
- Format:
public void setJccIntAtName(String parameterMarkerName, int x) throws java.sql.SQLException
Assigns a value of type int to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The value of type int that is assigned to the parameter marker.
- setJccLongAtName
- Format:
public void setJccLongAtName(String parameterMarkerName, long x) throws java.sql.SQLException
Assigns a value of type long to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The value of type long that is assigned to the parameter marker.
- setJccNullAtName
- Format:
public void setJccNullAtName(String parameterMarkerName, int jdbcType) throws java.sql.SQLException public void setJccNullAtName(String parameterMarkerName, int jdbcType, String typeName) throws java.sql.SQLException
Assigns the SQL NULL value to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- jdbcType
- The JDBC type code of the NULL value that is assigned to the parameter marker, as defined in java.sql.Types.
- typeName
- If jdbcType is java.sql.Types.DISTINCT or java.sql.Types.REF, the fully-qualified name of the SQL user-defined type of the NULL value that is assigned to the parameter marker.
- setJccObjectAtName
- Formats:
public void setJccObjectAtName(String parameterMarkerName, java.sql.Object x) throws java.sql.SQLException public void setJccObjectAtName(String parameterMarkerName, java.sql.Object x, int targetJdbcType) throws java.sql.SQLException public void setJccObjectAtName(String parameterMarkerName, java.sql.Object x, int targetJdbcType, int scale) throws java.sql.SQLException
Assigns a value with type java.lang.Object to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The value with type Object that is assigned to the parameter marker.
- targetJdbcType
- The data type, as defined in java.sql.Types, that is assigned to the input value when it is sent to the data source.
- scale
- The scale of the value that is assigned to the parameter marker.
This parameter applies only to these cases:
- If targetJdbcType is java.sql.Types.DECIMAL or java.sql.Types.NUMERIC, scale is the number of digits to the right of the decimal point.
- If x has type java.io.InputStream or java.io.Reader, scale is the this is the length of the data in the Stream or Reader object.
- setJccShortAtName
- Format:
public void setJccShortAtName(String parameterMarkerName, short x) throws java.sql.SQLException
Assigns a value of type short to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The value of type short that is assigned to the parameter marker.
- setJccSQLXMLAtName
- Format:
public void setJccSQLXMLAtName(String parameterMarkerName, java.sql.SQLXML x) throws java.sql.SQLException
Assigns a value of type java.sql.SQLXML to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).This method is supported only for connections to Db2® on Linux®, UNIX, and Windows systems Version 9.1 or later or Db2 for z/OS® Version 9 or later.
Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The value of type java.sql.SQLXML that is assigned to the parameter marker.
- setJccStringAtName
- Format:
public void setJccStringAtName(String parameterMarkerName, String x) throws java.sql.SQLException
Assigns a value of type String to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The value of type String that is assigned to the parameter marker.
- setJccTimeAtName
- Formats:
public void setJccTimeAtName(String parameterMarkerName, java.sql.Time x) throws java.sql.SQLException public void setJccTimeAtName(String parameterMarkerName, java.sql.Time x, java.util.Calendar cal) throws java.sql.SQLException
Assigns a java.sql.Time value to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The java.sql.Time value that is assigned to the parameter marker.
- cal
- The java.util.Calendar object that the IBM Data Server Driver for JDBC and SQLJ uses to construct the time.
- setJccTimestampAtName
- Formats:
public void setJccTimestampAtName(String parameterMarkerName, java.sql.Timestamp x) throws java.sql.SQLException public void setJccTimestampAtName(String parameterMarkerName, java.sql.Timestamp x, java.util.Calendar cal) throws java.sql.SQLException
Assigns a java.sql.Timestamp value to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The java.sql.Timestamp value that is assigned to the parameter marker.
- cal
- The java.util.Calendar object that the IBM Data Server Driver for JDBC and SQLJ uses to construct the timestamp.
- setJccUnicodeStreamAtName
- Format:
public void setJccUnicodeStreamAtName(String parameterMarkerName, java.io.InputStream x, int length) throws java.sql.SQLException
Assigns a Unicode value in a java.io.InputStream to a named parameter marker.
This method can be called only if the enableNamedParameterMarkers property is set to
DB2BaseDataSource.YES
(1).Parameters:- parameterMarkerName
- The name of the parameter marker to which a value is assigned.
- x
- The Unicode java.io.InputStream value that is assigned to the parameter marker.
- length
- The number of bytes of the java.io.InputStream value that are assigned to the parameter marker.
- setDBDefault
- Formats:
public void setDBDefault(int parameterIndex) throws SQLException
Assigns the default value to the specified parameter. Execution of setDBDefault produces the same results as using the literal DEFAULT in the SQL string, instead of the parameter.
Parameters:- parameterIndex
- The number of the parameter whose value is being updated.
This method is not supported for connections to IBM Informix data sources.
- setDBUnassigned
- Formats:
public void setDBUnassigned(int parameterIndex) throws SQLException
Does not assign a value to the specified parameter. Execution of setDBUnassigned produces the same result as if the specified parameter had not appeared in the SQL string.
Parameters:- parameterIndex
- The number of the parameter whose value is to be unassigned.
This method is not supported for connections to IBM Informix data sources.