Using DB2ResultSet methods or DB2PreparedStatement constants to provide extended parameter information
Use DB2ResultSet methods or ResultSet methods with DB2PreparedStatement constants to assign default values to target columns in a DB2ResultSet.
About this task
Procedure
Example
The following code inserts a row into a ResultSet with the default value in the second column, and does not modify the value in the first column. The numbers to the right of selected statements correspond to the previously described steps.
import java.sql.*;
import com.ibm.db2.jcc.*;
Connection conn;
…
PreparedStatement p = conn.prepareStatement ( 1
"SELECT MGRNO, LOCATION " +
"FROM DEPARTMENT");
ResultSet rs = p.executeQuery (); 3
rs.next ();
rs.moveToInsertRow(); 4
((DB2ResultSet)rs).updateDBDefault (2); 5
rs.insertRow(); 6
…
rs.close(); // Close ResultSet
p.close(); // Close PreparedStatement
The following code uses the ResultSet interface with DB2PreparedStatement constants to perform the same function as in the previous example. The numbers to the right of selected statements correspond to the previously described steps.
import java.sql.*;
import com.ibm.db2.jcc.*;
Connection conn;
…
PreparedStatement p = conn.prepareStatement ( 1
"SELECT MGRNO, LOCATION " +
"FROM DEPARTMENT");
ResultSet rs = p.executeQuery (); 3
rs.next ();
rs.moveToInsertRow(); 4
rs.updateObject (2, 5
DB2PreparedStatement.DB_PARAMETER_DEFAULT);
rs.insertRow(); 6
…
rs.close(); // Close ResultSet
p.close(); // Close PreparedStatement