The table below lists the setXXX methods of the PreparedStatement and CallableStatement classes 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 18-68 JDBC SQL types mapped by the setXXX methods
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.
The following tables show the mapping between the setXXX methods of the PreparedStatement and CallableStatement classes and JDBC's SQL types.
Table 18-69 Mapping between the setXXX methods 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#4 |
setArray |
-- |
-- |
-- |
-- |
-- |
-- |
setBlob |
-- |
-- |
-- |
-- |
-- |
-- |
Table 18-70 Mapping between the setXXX methods and JDBC's SQL data types (2/2)
setXXX method |
JDBC's SQL data type |
VARCHAR |
DATE |
TIME |
TIMESTAMP |
LONGVARBINARY |
ARRAY |
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.#5 |
-- |
Y |
-- |
-- |
setTime |
Y |
-- |
Rec. |
Y |
-- |
-- |
setTimestamp#1 |
Y |
Y |
-- |
Rec. |
-- |
-- |
setAsciiStream |
Y |
-- |
-- |
-- |
Y |
-- |
setBinaryStream |
-- |
-- |
-- |
-- |
Y |
-- |
setObject#2 |
Y |
Y |
Y |
Y |
Y |
-- |
setCharacterStream |
Y#4 |
-- |
-- |
-- |
Y#4 |
-- |
setArray |
-- |
-- |
-- |
-- |
-- |
Y |
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 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, as applicable:
- 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.
- #4
- 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]](FIGURE/ZU170001.GIF)
- #5
- 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.
All Rights Reserved. Copyright (C) 2011, Hitachi, Ltd.