Scalable Database Server, HiRDB Version 8 UAP Development Guide

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

17.8.4 Data conversion of TIME, DATE, and TIMESTAMP columns

Organization of this subsection
(1) setTime, setDate, setTimestamp, and setString methods
(2) getTime, getDate, and getTimestamp methods

(1) setTime, setDate, setTimestamp, and setString methods

This item explains the conversion process when data of HiRDB's TIME, DATE, 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 HiRDB's TIME, DATE, or TIMESTAMP data type, data conversion takes place according to the HiRDB data type.

Table 17-36 shows the conversion processing for combinations of the different column data types and methods.

Table 17-36 Conversion processing for combinations of the TIME, DATE, and TIMESTAMP types and the setXXX methods

setXXX method HiRDB data type
TIME type DATE type TIMESTAMP type
setTime(Time Obj)#1 Stores the UAP setting value in the database without any conversion. Throws an SQLException. Stores in the database data that has 1970-01-01 added before the UAP setting value hh:mm:ss[.000000].
setDate(Date Obj)#2 Throws an SQLException. Stores the UAP setting value in the database without any conversion. Stores data in the database that has 00:00:00[.000000] added after the UAP setting value yyyy-MM-DD.
setTimestamp(Timestamp Obj)#3 Throws an SQLException. Stores in the database the data formed when yyyy-MM-DD is removed from the UAP setting value. Stores the UAP setting value in the database without any conversion.
setString(character string in hh:mm:ss format) Converts the specified time with java.sql.Time.valueOf() and stores the result in the database.#5 Throws an SQLException. Throws an SQLException.
setString(character string in yyyy-MM-DD format) Throws an SQLException. Converts the specified date with java.sql.Date.valueOf() and stores the result in the database.#5 Throws an SQLException.
setString(character string in yyyy-MM-DD[Figure]hh:mm:ss[.ffffff] format)#4 Throws an SQLException. Throws an SQLException. Converts the specified date/time with java.sql.Timestamp.valueOf() and stores the result in the database.#5

Note:
If a non-existent date or time is specified, the specified value is returned by the Java Virtual Machine.

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

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

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

#4
For [.ffffff], the number of digits after the decimal point depends on the precision of HiRDB's TIMESTAMP type.
[Figure] represents a single-byte space character.

#5
The result when a non-existent date or time is specified depends on java.sql.Time.valueOf(), java.sql.Date.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 (switching from the Julian to the Gregorian calendar).

(2) getTime, getDate, and getTimestamp methods

This item explains the conversion process when data of HiRDB's TIME, DATE, TIMESTAMP or character string (CHAR, MCHAR, NCHAR, VARCHAR, MVARCHAR, or NVARCHAR) 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 HiRDB's TIME, DATE, TIMESTAMP, or character string data type, data conversion takes place according to the HiRDB data type.

Table 17-37 shows the conversion processing for combinations of the different column data types and methods.

Table 17-37 Conversion processing for combinations of the TIME, DATE, TIMESTAMP, and character string types and the getXXX methods

getXXX method HiRDB data type
TIME type DATE type TIMESTAMP type Character string type
getTime()#2 Gets the value stored in the database and sets it as the java.sql.Time object without any conversion.#1 Throws an SQLException. Removes the hour:minute:second data from the TIMESTAMP data retrieved from the database and sets the result as the java.sql.Time object.#1 Gets only an hh:mm:ss character string expression of the TIME type as the java.sql.Time object. For other expressions, the method throws an exception.
getDate()#2 Throws an SQLException. Gets the value stored in the database and sets it as the java.sql.Date object without any conversion.#1 Removes the year-month-day data from the TIMESTAMP data retrieved from the database and sets the result as the java.sql.Date object.#1 Gets only a yyyy-MM-DD character string expression of the DATE type as the java.sql.Date object. For other expressions, the method throws an exception.
getTimestamp()#2 Throws an SQLException. Appends 00:00:00.000000 to the DATE data retrieved from the database and sets the result as the java.sql.Timestamp object. Gets the value stored in the database and sets it as the java.sql.Timestamp object without any conversion. Gets only a yyyy-MM-DD[Figure]hh:mm:ss[.ffffff] character string expression of the TIMESTAMP type as the java.sql.Timestamp object ([Figure] is a single-byte space character). For other expressions, the method throws an SQLException.

Legend:
Character string types: CHAR, MCHAR, NCHAR, VARCHAR, MVARCHAR, and NVARCHAR

#1
The setting value of an unspecified date item (year-month-day) is 1970-01-01, and the setting value of an unspecified time item (hour:minute:second.millisecond) is 00:00:00.000000.

#2
The date and time stored in the database may 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 calendar).