Scalable Database Server, HiRDB Version 8 UAP Development Guide

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

16.3.3 Added data types

Several new JDBC SQL types have been added to JDBC2.0 basic standard. They are as follows:

Note that the JDBC driver can use only the ARRAY JDBC SQL type.

Organization of this subsection
(1) Data mapping during retrieval data acquisition
(2) Data mapping when the ? parameter is specified

(1) Data mapping during retrieval data acquisition

Tables 16-6 and 16-7 show the mapping between the getXXX methods and JDBC SQL types of ResultSet and CallableStatement.

If a getXXX method is called for an unsupported JDBC SQL type, the JDBC driver throws an SQLException. For details about the JDBC SQL types supported by the connected database, see 16.12 Data types and character codes.

Note that the getCharacterStream method has been added because the getUnicodeStream method is no longer recommended in the JDBC2.0 basic standard.

Table 16-6 Mapping between the getXXX methods and JDBC SQL types of ResultSet and CallableStatement (1/2)

getXXX method JDBC SQL type
SMALLINT INTEGER FLOAT REAL DECIMAL CHAR
getByte M M M M M M2
getShort R M M M M M2
getInt M R M M M M2
getLong M M M M M M2
getFloat M M M R M M2
getDouble M M R M M M2
getBigDecimal M M M M R M2
getBoolean M M M M M M
getString M M M M M R
getBytes [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
getDate [Figure] [Figure] [Figure] [Figure] [Figure] M2
getTime [Figure] [Figure] [Figure] [Figure] [Figure] M2
getTimestamp [Figure] [Figure] [Figure] [Figure] [Figure] M2
getAsciiStream [Figure] [Figure] [Figure] [Figure] [Figure] M
getUnicodeStream [Figure] [Figure] [Figure] [Figure] [Figure] M
getBinaryStream [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
getObject M M M M M M
getCharacterStream [Figure] [Figure] [Figure] [Figure] [Figure] M
getArray [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
getBlob [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
getClob1 [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
getRef1 [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]

Legend:
R: Mapping is recommended.
M: Can be mapped.
[Figure]: Cannot be mapped.

1 Not supported by the JDBC driver.

2 When the data from the character string is converted, any single-byte spaces that precede or follow the character string data acquired from the database are stripped, before the data is converted to the Java data type that is to be returned by the getXXX method.

Note the following when you convert data to a Java data type:
  • If there is an expression following the decimal point in text string data and the getByte, getInt, getShort, or getLong method is executed, the data following the decimal point is truncated and only the integer digits are converted and returned.
  • If character string data contains double-byte characters, the method throws an SQLException. Double-byte characters include double-byte spaces filled when a character string shorter than the definition length of a column is stored in an NCHAR column.
  • If overflow occurs when character string data is converted to the Java data type, the method throws an SQLException.
  • If the execution environment of the UAP is JDK or JRE 1.2 and the character string data uses exponential notation (such as 1.23E-23) and the getLong method or getBigDecimal method is executed, the method throws an SQLException.

    Table 16-7 Mapping between the getXXX methods and JDBC SQL types of ResultSet and CallableStatement (2/2)

    getXXX method JDBC SQL type
    VARCHAR DATE TIME TIMESTAMP LONGVARBINARY ARRAY
    getByte M2 [Figure] [Figure] [Figure] [Figure] [Figure]
    getShort M2 [Figure] [Figure] [Figure] [Figure] [Figure]
    getInt M2 [Figure] [Figure] [Figure] [Figure] [Figure]
    getLong M2 [Figure] [Figure] [Figure] [Figure] [Figure]
    getFloat M2 [Figure] [Figure] [Figure] [Figure] [Figure]
    getDouble M2 [Figure] [Figure] [Figure] [Figure] [Figure]
    getBigDecimal M2 [Figure] [Figure] [Figure] [Figure] [Figure]
    getBoolean M2 [Figure] [Figure] [Figure] [Figure] [Figure]
    getString R M M M M [Figure]
    getBytes [Figure] [Figure] [Figure] [Figure] M [Figure]
    getDate M2 R3 [Figure] M [Figure] [Figure]
    getTime M2 [Figure] R M [Figure] [Figure]
    getTimestamp M2 M [Figure] R [Figure] [Figure]
    getAsciiStream M [Figure] [Figure] [Figure] M [Figure]
    getUnicodeStream M [Figure] [Figure] [Figure] M [Figure]
    getBinaryStream [Figure] [Figure] [Figure] [Figure] R [Figure]
    getObject M M M M M M
    getCharacterStream M [Figure] [Figure] [Figure] M [Figure]
    getArray [Figure] [Figure] [Figure] [Figure] [Figure] R
    getBlob [Figure] [Figure] [Figure] [Figure] M [Figure]
    getClob1 [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
    getRef1 [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]

Legend:
R: Mapping is recommended.
M: Can be mapped.
[Figure]: Cannot be mapped.

1 Not supported by the JDBC driver.

2 In data conversion from character string data, any single-byte spaces that exist before and after the character string data is acquired from the database are removed, and then the data is converted to the Java data type returned by the getXXX method.

Note the following when you convert data to a Java data type:
  • If there is an expression following the decimal point in text string data and the getByte, getInt, getShort, or getLong method is executed, the data following the decimal point is truncated and only the integer digits are converted and returned.
  • If character string data contains double-byte characters, the method throws an SQLException. Double-byte characters include double-byte spaces filled when a character string shorter than the definition length of a column is stored in an NCHAR column.
  • If overflow occurs when character string data is converted to the Java data type, the method throws an SQLException.
  • If the execution environment of the UAP is JDK or JRE 1.2 and the character string data uses exponential notation (such as 1.23E-23) and the getLong method or getBigDecimal method is executed, the method throws an SQLException.

3 When the JDBC SQL type is the DATA type and conversion is executed by specifying a java.util.Calendar object for the setDate method, the specified java.util.Calendar object is used for data conversion, time data is truncated, and only date data is stored in the database. In such a case, even if you specify the java.util.Calendar object for the getDate method to acquire the data stored using the setDate method, a different date than the date specified for the setDate method may be acquired.

Example:
The following is an example of when a java.util.Calendar object using Universal Time (UTC) is specified for the setDate and getDate methods in a UAP that uses Japanese standard time as the default time zone.
When you specify a java.sql.Date object that represents 2005-10-03 for the setDate method and then execute it, the JDBC driver adds 00:00:00 in the time part, and then stores the date part as 2005-10-02 in the database by delaying 9 hours because of the time zone difference. If this data is acquired using the getDate method, the date part 2005-10-02 is acquired from the database and 00:00:00 is added for the time part, and then 2005-10-02 09:00:00 is set by advancing 9 hours because of the time zone difference. Because of this, 2005-10-02 is set in the java.sql.Date object return value of the getDate method, which is different from the 2005-10-03 date specified for the setDate method.

(2) Data mapping when the ? parameter is specified

Table 16-8 shows setXXX methods and JDBC SQL types to be mapped for the PreparedStatement class and CallableStatement. For an unsupported JDBC SQL type, the setXXX method throws an SQLException. For details about the JDBC SQL types supported by the connected database, see 16.12 Data types and character codes.

Note that the setCharacterStream method has been added because the setUnicodeStream method is no longer recommended in the JDBC2.0 basic standard.

Table 16-8 setXXX methods and JDBC SQL types to be mapped for PreparedStatement class

PreparedStatement class's setXXX method JDBC SQL type to be mapped
setCharacterStream CHAR, VARCHAR, or LONGVARCHAR
SetRef* REF
setBlob LONGVARBINARY
setClob* CLOB
setArray ARRAY

* Not supported by the JDBC driver.

Tables 16-9 and 16-10 show the mapping between the setXXX methods and JDBC SQL types of PreparedStatement and CallableStatement.

Table 16-9 Mapping between the setXXX methods and JDBC SQL types of PreparedStatement and CallableStatement (1/2)

setXXX method JDBC SQL type
SMALLINT INTEGER FLOAT REAL DECIMAL CHAR
setByte M M M M M M
setShort R M M M M M
setInt M R M M M M
setLong M M M M M M
setFloat M M M R M M
setDouble M M R M M M
setBigDecimal M M M M R M
setBoolean M M M M M M
setString M M M M M R
setBytes [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
setDate [Figure] [Figure] [Figure] [Figure] [Figure] M
setTime [Figure] [Figure] [Figure] [Figure] [Figure] M
setTimestamp [Figure] [Figure] [Figure] [Figure] [Figure] M
setAsciiStream [Figure] [Figure] [Figure] [Figure] [Figure] M
setUnicodeStream [Figure] [Figure] [Figure] [Figure] [Figure] M
setBinaryStream [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
setObject M M M M M M
setCharacterStream [Figure] [Figure] [Figure] [Figure] [Figure] M
setArray [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
setBlob [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
setClob* [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
setRef* [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]

Legend:
R: Mapping is recommended.
M: Can be mapped. Note that data may be missing or a conversion error may occur depending on the format of source data.
[Figure]: Cannot be mapped.

* Not supported by the JDBC driver.

Table 16-10 Mapping between the setXXX methods and JDBC SQL types of PreparedStatement and CallableStatement (2/2)

setXXX method JDBC SQL type
VARCHAR DATE TIME TIMESTAMP LONGVARBINARY ARRAY
setByte M [Figure] [Figure] [Figure] [Figure] [Figure]
setShort M [Figure] [Figure] [Figure] [Figure] [Figure]
setInt M [Figure] [Figure] [Figure] [Figure] [Figure]
setLong M [Figure] [Figure] [Figure] [Figure] [Figure]
setFloat M [Figure] [Figure] [Figure] [Figure] [Figure]
setDouble M [Figure] [Figure] [Figure] [Figure] [Figure]
setBigDecimal M [Figure] [Figure] [Figure] [Figure] [Figure]
setBoolean M [Figure] [Figure] [Figure] [Figure] [Figure]
setString R M M M M [Figure]
setBytes [Figure] [Figure] [Figure] [Figure] M [Figure]
setDate M R2 [Figure] M [Figure] [Figure]
setTime M [Figure] R M [Figure] [Figure]
setTimestamp M M [Figure] R [Figure] [Figure]
setAsciiStream M [Figure] [Figure] [Figure] M [Figure]
setUnicodeStream M [Figure] [Figure] [Figure] M [Figure]
setBinaryStream [Figure] [Figure] [Figure] [Figure] R [Figure]
setObject M M M M M M
setCharacterStream M [Figure] [Figure] [Figure] M [Figure]
setArray [Figure] [Figure] [Figure] [Figure] [Figure] R
setBlob [Figure] [Figure] [Figure] [Figure] M [Figure]
setClob1 [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]
setRef1 [Figure] [Figure] [Figure] [Figure] [Figure] [Figure]

Legend:
R: Mapping is recommended.
M: Can be mapped. Note that data may be missing or a conversion error may occur depending on the format of source data.
[Figure]: Cannot be mapped.

1 Not supported by the JDBC driver.

2 When the JDBC SQL type is the DATA type and conversion is executed by specifying a java.util.Calendar object for the setDate method, the specified java.util.Calendar object is used for data conversion, time data is truncated, and only date data is stored in the database. In such a case, even if you specify the java.util.Calendar object for the getDate method to acquire the data stored using the setDate method, a different date than the date specified for the setDate method may be acquired.

Example:
The following is an example of what happens when a java.util.Calendar object using Universal Time (UTC) is specified for the setDate and getDate methods in a UAP that uses Japanese standard time as the default time zone.
When you specify a java.sql.Date object that represents 2005-10-03 for the setDate method, and then execute it, the JDBC driver adds 00:00:00 in the time part and then stores the date part as 2005-10-02 in the database by delaying 9 hours because of the time zone difference. If this data is acquired using the getDate method, the date part 2005-10-02 is acquired from the database and 00:00:00 is added for the time part, and then 2005-10-02 09:00:00 is set by advancing 9 hours because of the time zone difference. Because of this, 2005-10-02 is set in the java.sql.Date object return value of the getDate method, which is different from the 2005-10-03 date specified for the setDate method.