Scalable Database Server, HiRDB Version 8 UAP Development Guide

[Contents][Index][Back][Next]

17.8.3 Mapping when a ? parameter is set

Table 17-33 lists the setXXX methods of the PreparedStatement class and shows the corresponding JDBC SQL types that are mapped. If a JDBC SQL type cannot be used, the setXXX method throws an SQLException.

The setCharacterStream method has been added as a replacement for the setUnicodeStream method, because the JDBC2.0 basic standard does not recommend the latter method.

Table 17-33 JDBC SQL types mapped by the setXXX methods of the PreparedStatement class

setXXX method of PreparedStatement class Mapped JDBC SQL type
setCharacterStream CHAR or VARCHAR
setRef# REF
setBlob LONGVARBINARY
setClob# CLOB
setArray ARRAY

#
The JDBC driver cannot use this method.

Tables 17-34 and 17-35 show the mapping between the setXXX methods of the PreparedStatement class and JDBC's various SQL types.

Table 17-34 Mapping between the setXXX methods of the PreparedStatement class and JDBC's SQL data types (1/2)

setXXX method JDBC's SQL data type
SMALLINT INTEGER FLOAT REAL DECIMAL#3 CHAR
setByte Y Y Y Y Y Y
setShort Rec. Y Y Y Y Y
setInt Y Rec. Y Y Y Y
setLong Y Y Y Y Y Y
setFloat Y Y Y Rec. Y Y
setDouble Y Y Rec. Y Y Y
setBigDecimal Y Y Y Y Rec. Y
setBoolean Y Y Y Y Y Y
setString Y Y Y Y Y Rec.
setBytes -- -- -- -- -- --
setDate -- -- -- -- -- Y
setTime -- -- -- -- -- Y
setTimestamp#1 -- -- -- -- -- Y
setAsciiStream -- -- -- -- -- Y
setBinaryStream -- -- -- -- -- --
setObject#2 Y Y Y Y Y Y
setCharacterStream -- -- -- -- -- Y#3
setBlob -- -- -- -- -- --

Legend:
Rec.: Mapping is recommended
Y: Can be mapped. Note, however, that data loss or a conversion error may occur depending on the format of the conversion-source data.
--: Cannot be mapped.

#1
If a setXXX method specifies a value for a ? parameter of HiRDB's TIMESTAMP data type, and the ? parameter and the value have different precisions for the fractional seconds part, the JDBC driver performs one of the following operations:
  • When the value has a larger fractional seconds precision than the ? parameter: truncates the fractional seconds part of the value.
  • When the value has a smaller fractional seconds precision than the ? parameter: expands the fractional seconds part of the value.

#2
Objects of the InputStream class and the Reader class (including subclasses) cannot be specified in the setObject method.

#3
If a setXXX method specifies a value for a ? parameter of HiRDB's DECIMAL data type, and the ? parameter and the value have different precisions and decimal scaling positions, the JDBC driver performs one of the following operations:
  • When the value has a larger precision than the ? parameter: throws an SQLException.
  • When the value has a smaller precision than the ? parameter: expands the precision.
  • When the value has a larger decimal scaling position than the ? parameter: truncates the value according to the actual scaling position.
  • When the value has a smaller decimal scaling position than the ? parameter: adds zeros to expand the decimal scaling position.

    Table 17-35 Mapping between the setXXX methods of the PreparedStatement class and JDBC's SQL data types (2/2)

    setXXX method JDBC's SQL data type
    VARCHAR DATE TIME TIMESTAMP LONGVARBINARY BLOB
    setByte Y -- -- -- -- --
    setShort Y -- -- -- -- --
    setInt Y -- -- -- -- --
    setLong Y -- -- -- -- --
    setFloat Y -- -- -- -- --
    setDouble Y -- -- -- -- --
    setBigDecimal Y -- -- -- -- --
    setBoolean Y -- -- - -- --
    setString Rec. Y Y Y Y --
    setBytes -- -- -- - Y --
    setDate Y Rec.#4 -- Y -- --
    setTime Y -- Rec. Y -- --
    setTimestamp#1 Y Y -- Rec. -- --
    setAsciiStream Y -- -- -- Y --
    setBinaryStream -- -- N -- Y --
    setObject#2 Y Y Y Y Y Y
    setCharacterStream Y#3 -- -- -- Y#3 --
    setBlob -- -- -- - Y --

Legend:
Rec.: Mapping is recommended
Y: Can be mapped. Note, however, that data loss or a conversion error may occur depending on the format of the conversion-source data.
--: Cannot be mapped.

#1
If a setXXX method specifies a value for a ? parameter of HiRDB's TIMESTAMP data type, and the ? parameter and the value have different precisions for the fractional seconds part, the JDBC driver performs one of the following operations:
  • If the value has a larger fractional seconds precision than the ? parameter: truncates the fractional seconds part of the value.
  • If the value has a smaller fractional seconds precision than the ? parameter: expands the fractional seconds part of the value.

#2
Objects of the InputStream class and the Reader class (including subclasses) cannot be specified in the setObject method.

#3
If the length of the data that can be retrieved from a java.io.Reader object is shorter than the length specified in the arguments, the JDBC driver adds zeros as shown below until the length specified in the arguments is reached:
[Figure]

#4
When the JDBC SQL type is the DATE type and a java.util.Calender object is specified in a setDate method that is then executed, the JDBC driver uses the specified java.util.Calendar object to convert the data, discards the time data, and stores only the date data in the database. Because the time data is discarded, if an application specifies a java.util.Calendar object in the getDate method and executes the method to retrieve the data that was stored with the setDate method, the retrieved date may differ from the one that was specified in the setDate method.
Example
In this example, the UAP uses Japan Standard Time as the default time zone and specifies a java.util.Calendar object that uses Greenwich Mean Time in the setDate and getDate methods.
When the UAP specifies a java.sql.Date object representing 2005-10-03 in the setDate method and executes the method, the JDBC driver supplements 00:00:00 to the time portion, and then subtracts 9 hours because of the time zone difference. The result is 2005-10-02 15:00:00, and the JDBC driver stores the date portion 2005-10-02 of the result in the database. When the UAP uses the getDate method to retrieve this data, the JDBC driver gets the date portion 2005-10-02 from the database, supplements 00:00:00 to the time portion, and adds 9 hours because of the time difference to produce 2005-10-02 09:00:00. Consequently, in the java.sql.Date object used as the return value of the getDate method, the JDBC driver sets 2005-10-02, which differs from 2005-10-03, which was specified in the SetDate method.