Tables 17-31 and 17-32 show the mapping between getXXX methods of the ResultSet class and JDBC's SQL data types. If a getXXX method is called for one of JDBC's unmappable SQL data types, the JDBC driver throws an SQLException.
Table 17-31 Mapping between getXXX methods of the ResultSet class and JDBC's SQL data types (1/2)
getXXX method |
JDBC's SQL data type |
SMALLINT |
INTEGER |
FLOAT |
REAL |
DECIMAL |
getByte |
Y |
Y |
Y |
Y |
Y |
getShort |
Rec. |
Y |
Y |
Y |
Y |
getInt |
Y |
Rec. |
Y |
Y |
Y |
getLong |
Y |
Y |
Y |
Y |
Y |
getFloat |
Y |
Y |
Y |
Rec. |
Y |
getDouble |
Y |
Y |
Rec. |
Y |
Y |
getBigDecimal |
Y |
Y |
Y |
Y |
Rec. |
getBoolean |
Y |
Y |
Y |
Y |
Y |
getString |
Y |
Y |
Y |
Y |
Y |
getBytes |
-- |
-- |
-- |
-- |
-- |
getDate |
-- |
-- |
-- |
-- |
-- |
getTime |
-- |
-- |
-- |
-- |
-- |
getTimestamp |
-- |
-- |
-- |
-- |
-- |
getAsciiStream |
-- |
-- |
-- |
-- |
-- |
getBinaryStream |
-- |
-- |
-- |
-- |
-- |
getObject |
Y |
Y |
Y |
Y |
Y |
getCharacterStream |
-- |
-- |
-- |
-- |
-- |
getBlob |
-- |
-- |
-- |
-- |
-- |
- Legend:
- Rec.: Mapping is recommended.
- Y: Can be mapped. Note, however, that data loss or an error may occur depending on the format of the mapping-source data.
- --: Cannot be mapped.
Table 17-32 Mapping between getXXX methods of the ResultSet class and JDBC's SQL data types (2/2)
getXXX method |
JDBC's SQL data type |
CHAR |
VARCHAR |
DATE |
TIMESTAMP |
LONGVARBINARY |
getByte |
Y#1 |
Y#1 |
-- |
-- |
-- |
getShort |
Y#1 |
Y#1 |
-- |
-- |
-- |
getInt |
Y#1 |
Y#1 |
-- |
-- |
-- |
getLong |
Y#1 |
Y#1 |
-- |
-- |
-- |
getFloat |
Y#1 |
Y#1 |
-- |
-- |
-- |
getDouble |
Y#1 |
Y#1 |
-- |
-- |
-- |
getBigDecimal |
Y#1 |
Y#1 |
-- |
-- |
-- |
getBoolean |
Y |
Y |
-- |
-- |
-- |
getString |
Rec. |
Rec. |
Y |
Y |
Y |
getBytes |
-- |
-- |
-- |
-- |
Y |
getDate |
Y#1 |
Y#1 |
Rec.#2 |
Y |
-- |
getTime |
Y#1 |
Y#1 |
-- |
Y |
-- |
getTimestamp |
Y#1 |
Y#1 |
Y |
Rec. |
-- |
getAsciiStream |
Y |
Y |
-- |
-- |
Y |
getBinaryStream |
-- |
-- |
-- |
-- |
Rec. |
getObject |
Y |
Y |
Y |
Y |
Y |
getCharacterStream |
Y |
Y |
-- |
-- |
Y |
getBlob |
-- |
-- |
-- |
-- |
-- |
- 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 there are any single-byte spaces preceding or following the character string data retrieved from the database during conversion by this method, the JDBC driver removes them. After removing the single-byte spaces, the JDBC driver converts the data to the Java data type returned by the getXXX method.
Note the following items when data is converted to a Java data type:
- If the character string data contains a fractional part and the getByte, getInt, getShort, or getLong method is executed, the JDBC driver discards the fractional part and then converts and returns only the integer.
- If the character string data contains double-byte characters, the JDBC driver throws an SQLException without converting the data. Double-byte characters include double-byte spaces used for padding when a character string shorter than the defined column length is stored in a column of HiRDB's NCHAR data type.
- If overflow occurs after character string data is converted to a Java data type, the JDBC driver throws an SQLException.
- #2
- 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, as was specified in the SetDate method.
All Rights Reserved. Copyright (C) 2007, Hitachi, Ltd.