Use of PreparedStatement.setTimestamp to set values in TIMESTAMP WITH TIME ZONE columns

When you use PreparedStatement.setTimestamp to set a value in a TIMESTAMP WITH TIME ZONE column, you should specify a com.ibm.db2.jcc.DBTimestamp object for the input value.

Use of a com.ibm.db2.jcc.DBTimestamp object ensures that the correct time zone is assigned to the target column.

In certain cases, the target data type for a table update is not known. Possible reasons are:

  • The deferPrepares and sendDataAsIs properties are set so that the target data type is not known.
  • The input parameter is for a CALL statement, and the stored procedure is on a Db2 for z/OS® data server.

If the target data type is not known, the IBM® Data Server Driver for JDBC and SQLJ must choose a target data type. When an input parameter has type com.ibm.db2.jcc.DBTimestamp, and the target data server supports TIMESTAMP WITH TIME ZONE, the driver always chooses TIMESTAMP with TIMEZONE as the target data type.

Before version 3.63 or 4.13 of the IBM Data Server Driver for JDBC and SQLJ, if the target data type is not known, the target data server supports TIMESTAMP WITH TIME ZONE, and the input data type is java.sql.Timestamp, the driver chooses TIMESTAMP WITH TIME ZONE as the target type.

Starting with version 3.63 or 4.13, if the target data type is not known, the target data server supports TIMESTAMP WITH TIME ZONE, and the input data type is java.sql.Timestamp, the driver chooses TIMESTAMP WITH TIME ZONE as the target type, except when the input object has a value of 0001-01-01-00:00:00.000000 or 9999-12-31-23:59:59.999999. In those cases, the driver chooses the TIMESTAMP type, without a time zone. Use of the TIMESTAMP data type in those two cases prevents an overflow condition from occurring because of adjustment of the value for the implied time zone. The implied time zone is the time zone of the Java virtual machine (JVM). Starting with version 3.65 or 4.15, the timestamps for which the driver chooses the TIMESTAMP type, without the time zone, are 0001-01-01, with any time, or 9999-12-31, with any time.

Migration consideration

TIMESTAMP WITH TIME ZONE is first supported in Db2 for z/OS Version 10 new-function mode. Before Version 10 new-function mode, if the value that is assigned to a column (the second parameter of PreparedStatement.setTimestamp) has the java.sql.Timestamp data type, and the column data type is not known, the IBM Data Server Driver for JDBC and SQLJ chooses TIMESTAMP as the column data type. However, starting with Db2 for z/OS Version 10 new-function mode, unless the value that is assigned to the column is 0001-01-01-00:00:00.000000 or 9999-12-31-23:59:59.999999, the driver chooses TIMESTAMP WITH TIME ZONE as the column data type. If the driver chooses the TIMESTAMP data type, and the column type is actually TIMESTAMP WITH TIME ZONE, the database manager sets the time zone in the target column using the value of the IMPLICIT_TIMEZONE DECP value. This value might differ from the value that is inserted prior to Version 10 new-function mode.

To produce the same results before and after new-function mode when PreparedStatement.setTimestamp is executed, specify a com.ibm.db2.jcc.DBTimestamp value as the second parameter.