DB2 10.5 for Linux, UNIX, and Windows

DB2Statement interface

The com.ibm.db2.jcc.DB2Statement interface extends the java.sql.Statement interface.

DB2Statement implements the java.sql.Wrapper interface.

DB2Statement fields

The following fields are defined only for the IBM® Data Server Driver for JDBC and SQLJ.

public static final int RETURN_OPTLOCK_COLUMN_NONE = 0
public static final int RETURN_OPTLOCK_COLUMN_ALWAYS = 1
public static final int RETURN_OPTLOCK_COLUMN_NO_FALSE_NEGATIVES = 2
These values are arguments for the DB2Statement.executeDB2OptimisticLockingQuery method.

DB2Statement methods

The following methods are defined only for the IBM Data Server Driver for JDBC and SQLJ.

executeDB2OptimisticLockingQuery
Format:
public java.sql.ResultSet DB2Statement.executeDB2OptimisticLockingQuery(
  String sql, 
  int returnOptLockingColumn)
  throws java.sql.SQLException

Executes an SQL query statement, and returns a ResultSet that contains optimistic locking information, if it is requested.

Parameter descriptions:
sql
An SQL SELECT statement that returns a single ResultSet.
returnOptimisticLockingColumns
Specifies whether optimistic locking columns are returned. Possible values are:
Table 1. Values for the returnOptimisticLockingColumns parameter
Value Description
DB2Statement.RETURN_OPTLOCK_COLUMN_NONE (0) Do not return optimistic locking columns.
DB2Statement.RETURN_OPTLOCK_COLUMN_ALWAYS (1) Add row change columns to the result set even if they do not uniquely represent a single row. This setting is equivalent to the database prepare attribute WITH ROW CHANGE COLUMNS POSSIBLY DISTINCT.
DB2Statement.RETURN_OPTLOCK_COLUMN_NO_FALSE_NEGATIVES (2) Add row change columns to the result set only if they uniquely represent a single row. This setting is equivalent to the database prepare attribute WITH ROW CHANGE COLUMNS ALWAYS DISTINCT.
getAffectedRowCount
Format:
public int getAffectedRowCount()
  throws java.sql.SQLException

Returns the number of rows that are affected by successful execution of an SQL statement. If the SQL statement is INSERT, UPDATE, or DELETE, getAffectedRowCount returns the same value that is returned by java.sql.Statement.getUpdateCount.

The value that is returned by getAffectedRowCount is the same information that is returned by the data server in the SQLCA after successful execution of an SQL statement.

getDB2ClientProgramId
Format:
public String getDB2ClientProgramId()
  throws java.sql.SQLException

Returns the user-defined client program identifier for the connection, which is stored on the data source.

getDB2ClientProgramId does not apply to DB2® for Linux, UNIX, and Windows data servers.

setDB2ClientProgramId
Format:
public abstract void setDB2ClientProgramId(String program-ID) 
  throws java.sql.SQLException

Sets a user-defined program identifier for the connection on a data server. That program identifier is an 80-byte string that is used to identify the caller.

setDB2ClientProgramId does not apply to DB2 for Linux, UNIX, and Windows data servers.

The DB2 for z/OS® server places the string in IFCID 316 trace records along with other statistics, so that you can identify which program is associated with a particular SQL statement.

getIDSBigSerial
Format:
public int getIDSBigSerial() 
  throws java.sql.SQLException

Retrieves an automatically generated key from a BIGSERIAL column after the automatically generated key was inserted by a previously executed INSERT statement.

The following conditions must be true for getIDSBigSerial to execute successfully:
  • The INSERT statement is the last SQL statement that is executed before this method is called.
  • The table into which the row is inserted contains a BIGSERIAL column.
  • The form of the JDBC Connection.prepareStatement method or Statement.executeUpdate method that prepares or executes the INSERT statement does not have parameters that request automatically generated keys.

This method applies only to connections to IBM Informix® databases.

getIDSSerial
Format:
public int getIDSSerial() 
  throws java.sql.SQLException

Retrieves an automatically generated key from a SERIAL column after the automatically generated key was inserted by a previously executed INSERT statement.

The following conditions must be true for getIDSSerial to execute successfully:
  • The INSERT statement is the last SQL statement that is executed before this method is called.
  • The table into which the row is inserted contains a SERIAL column.
  • The form of the JDBC Connection.prepareStatement method or Statement.executeUpdate method that prepares or executes the INSERT statement does not have parameters that request automatically generated keys.

This method applies only to connections to IBM Informix databases.

getIDSSerial8
Format:
public long getIDSSerial8() 
  throws java.sql.SQLException

Retrieves an automatically generated key from a SERIAL8 column after the automatically generated key was inserted by a previously executed INSERT statement.

The following conditions must be true for getIDSSerial8 to execute successfully:
  • The INSERT statement is the last SQL statement that is executed before this method is called.
  • The table into which the row is inserted contains a SERIAL8 column.
  • The form of the JDBC Connection.prepareStatement method or Statement.executeUpdate method that prepares or executes the INSERT statement does not have parameters that request automatically generated keys.

This method applies only to connections to IBM Informix data sources.

getIDSSQLStatementOffSet
Format:
public int getIDSSQLStatementOffSet()
  throws java.sql.SQLException

After an SQL statement executes on an IBM Informix data source, if the statement has a syntax error, getIDSSQLStatementOffSet returns the offset into the statement text of the syntax error.

getIDSSQLStatementOffSet returns:
  • 0, if the statement does not have a syntax error.
  • -1, if the data source is not IBM Informix.

This method applies only to connections to IBM Informix data sources.