Hitachi

Hitachi Advanced Database Application Development Guide


7.6.2 Data conversion process

This subsection explains the data conversion process when setXXX and getXXX methods are executed.

Organization of this subsection

(1) Data conversion process during execution of a setXXX method (for DATE, TIME or TIMESTAMP type)

This subsection explains the conversion process when data of HADB's DATE, TIME or TIMESTAMP data type is set in the setTime, setDate, setTimestamp, or setString method.

When the setTime, setDate, setTimestamp, or setString method is used to set data in a column of HADB's DATE, TIME or TIMESTAMP data type, data conversion takes place according to the rules described in the following table.

Table 7‒9: Conversion process during execution of the setXXX methods

Method executed

Conversion process for DATE type

Conversion process for TIME type

Conversion process for TIMESTAMP type

setDate(Date Obj)#1

Stores the application program settings in the database without performing conversion.

00:00:00 is stored in the database.

Stores in the database the data with 00:00:00 added after the application program setting for YYYY-MM-DD.

setTime(Time Obj)#2

Throws an SQLException.

The data for the application program setting for hh:mm:ss.fff is stored in the database.

Stores in the database the data with 1970-01-01 added before the application program setting for hh:mm:ss.fff.

setTimestamp(Timestamp Obj)#3

Stores in the database the data formed when YYYY-MM-DD is removed from the application program setting.

The data obtained by extracting hh:mm:ss.fffffffff from the application program setting is stored in the database.

The data for the application program setting for YYYY-MM-DDΔhh:mm:ss.fffffffff is stored in the database.#4

setString (character string in YYYY-MM-DD format)

Converts the specified date with java.sql.Date.valueOf() and stores the result in the database.#5

00:00:00 is stored in the database.

Throws an SQLException.

setString (character string in hh:mm:ss[.f...] format)

Throws an SQLException.

The data for the application program setting for hh:mm:ss[.f...] is stored in the database.

Throws an SQLException.

setString (character string in YYYY-MM-DDΔhh:mm:ss[.f...] format)#4

Throws an SQLException.

The data for the application program setting for hh:mm:ss[.f...] is stored in the database.

The data for the application program setting for YYYY-MM-DDΔhh:mm:ss[.f...] is stored in the database.#5

Note

If a non-existent date or time is specified, the Java Virtual Machine (JVM) returns the specified value.

#1

Date Obj is an object that has the value of the java.sql.Date object with the format year-month-date.

#2

Time Obj is an object that has the value of the java.sql.Time object with the format hour:minute:second:millisecond.

#3

Timestamp Obj is an object that has the value of the java.sql.Timestamp object with the format year-month-date hour:minute:second:nanosecond.

#4

Δ represents a space.

#5

The result when a non-existent date or time is specified depends on java.sql.Date.valueOf(), java.sql.Time.valueOf(), or java.sql.Timestamp.valueOf().

Example 1: 25:00:00 becomes 01:00:00.

Example 2: 2000-01-32 becomes 2000-02-01.

Example 3: 1582-10-05 becomes 1582-10-15 (the calendar switches from the Julian to the Gregorian).

(2) Data conversion process during execution of a getXXX method (for DATE, TIME, TIMESTAMP, or character string type)

This subsection explains the conversion process when data of HADB's DATE, TIME, TIMESTAMP, or character string (CHAR or VARCHAR) data type is set in the getTime, getDate, or getTimestamp method.

When the getTime, getDate, or getTimestamp method is used to set data in a column of HADB's DATE, TIME, TIMESTAMP, or character string data type, data conversion takes place according to the rules described in the following table.

Table 7‒10: Conversion process during execution of the getXXX methods

Method executed

Conversion process for DATE type

Conversion process for TIME type

Conversion process for TIMESTAMP type

Conversion process for character string type

getDate()#1

Gets the value stored in the database and sets it as the java.sql.Date object without performing conversion.#2

Gets the value as the java.sql.Date object that has the data 1970-01-01.#2

Removes the year-month-date data from the TIMESTAMP data retrieved from the database and sets the result as the java.sql.Date object.#2

Gets only a YYYY-MM-DD character string representation as the java.sql.Date object. For other representations, the method throws an SQLException.

getTime()#1

Throws an SQLException.

Removes the hour:minute:second.millisecond data from the TIME data retrieved from the database and sets the result as the java.sql.Time object.#2

Removes the hour:minute:second:millisecond data from the TIMESTAMP data retrieved from the database and sets the result as the java.sql.Time object.#2

Gets only an hh:mm:ss[.f...] character string representation as the java.sql.Time object. For other representations, the method throws an SQLException.

getTimestamp()#1

Appends 00:00:00.000000000 to the DATE data retrieved from the database and sets the result as the java.sql.Timestamp object.

Adds 1970-01-01 before the TIME data retrieved from the database and sets the result as the java.sql.Timestamp object.

Removes the year-month-dateΔhour:minute:second.nanosecond data from the TIMESTAMP data retrieved from the database and sets the result as the java.sql.Timestamp object.

Gets only a YYYY-MM-DDΔhh:mm:ss[.f...] character string representation of the TIMESTAMP type as the java.sql.Timestamp object (Δ is a space). For other expressions, the method throws an SQLException.

#1

The date and time stored in the database might be different from the date and time obtained from java.sql.Time, java.sql.Date, and java.sql.Timestamp:

Example 1: 25:00:00 becomes 01:00:00.

Example 2: 2000-01-32 becomes 2000-02-01.

Example 3: Both 1582-10-05 and 1582-10-15 become 1582-10-15 (the calendar switches from the Julian to the Gregorian).

#2

The setting for an unspecified date item (year-month-day) is 1970-01-01, and the setting for an unspecified time item (hour:minute:second) is 00:00:00.