Extended parameter information with the IBM Data Server Driver for JDBC and SQLJ
IBM Data Server Driver for JDBC and SQLJ-only methods and constants let you assign the default value or no value to table columns or ResultSet columns.
The data server must support extended indicators before you can use the methods that provide extended indicator information in your Java™ applications. If you call one of those methods against a data server that does not support extended indicators, an exception is thrown. Extended parameter information is supported by Db2® for z/OS® Version 10 or later, or Db2 on Linux®, UNIX, and Windows systems Version 9.7 or later.
The methods that provide extended parameter information are listed in the following table.
Extended parameter information methods | Purpose |
---|---|
DB2PreparedStatement.setDBDefault, DB2PreparedStatement.setJccDBDefaultAtName | Sets an input parameter to its default value. |
DB2PreparedStatement.setDBUnassigned, DB2PreparedStatement.setJccDBUnassignedAtName | Indicates that an input parameter is unassigned. This action yields the same behavior that would occur if the input parameter did not appear in the SQL statement text. |
DB2ResultSet.updateDBDefault | Sets a column value in the current ResultSet row to its default value. |
These methods are applicable only for parameter markers that appear in one of the following places:
- The SET list of an UPDATE statement
- The SET list of a MERGE statement
- The VALUES list of an INSERT statement
- The VALUES list of a MERGE statement
- The source table in a MERGE statement
- The SELECT list of an INSERT from SELECT statement
An SQLException is raised if you use these methods in any other context.
Alternatively, you can use the standard PreparedStatement.setObject or ResultSet.updateObject methods with IBM Data Server Driver for JDBC and SQLJ-only constants DB2PreparedStatement.DB_PARAMETER_DEFAULT or DB2PreparedStatement.DB_PARAMETER_UNASSIGNED to assign the default value or no value to parameters.
Extended parameter information can simplify application programs that have several input variables, each of which can send a value or the default value to the data server, or does not need to appear in the SQL statement. Instead of preparing separate statement strings for all combinations of variable values, you can prepare a single statement string. The resulting PreparedStatement object can be used in a homogeneous batch, whereas multiple different PreparedStatement objects cannot be used in a homogeneous batch.