Hitachi

Hitachi Advanced Database Application Development Guide


8.6.45 getObject(int columnIndex,Class<T> type)

Organization of this subsection

(1) Function

This method acquires the value in a specified column of the current row of a ResultSet object, and converts it to the Java data type of the specified class. The column whose value is to be acquired is specified in the argument of the method.

(2) Format

public synchronized <T> T getObject(int columnIndex,Class<T> type) throws SQLException

(3) Arguments

int columnIndex:

Specifies the column number.

Class<T> type:

Specifies the class that represents the Java data type after conversion. The value of the column specified by columnIndex is converted to the Java data type of the specified class.

The following table lists the conversions that are possible between data types. If you specify a combination that is not listed in the table, an error occurs.

Table 8‒37: Combinations of HADB data types and Java data types

HADB data type

Java data type (value specified for <T>)

ARRAY

Array

CHAR

String

VARCHAR

STRING

SMALLINT#1

Short

INTEGER#2

Integer

BIGINT

Long

DECIMAL

java.math.BigDecimal

NUMERIC

REAL

Float

DOUBLE PRECISION

Double

FLOAT

DATE

  • java.sql.Date

  • java.time.LocalDate

  • java.time.Instant

TIME

java.sql.Time

TIMESTAMP WITHOUT TIME ZONE

  • java.sql.Timestamp

  • java.time.LocalDateTime

  • java.time.Instant

TIMESTAMP WITH TIME ZONE

  • java.time.OffsetDateTime

  • java.time.LocalDateTime

  • java.time.Instant

  • java.time.ZonedDateTime

BINARY

byte[]

VARBINARY

ROW

BOOLEAN

Boolean

UUID

java.util.UUID

#1

If the integer data type format is in legacy format, the Java data type will be Integer.

#2

If the integer data type format is in legacy format, the Java data type will be Long.

(4) Return value

The value in the column is returned as an object of the specified class. The following table lists the relationship between retrieval results and return values.

Table 8‒38: Relationship between retrieval results and return values (getObject method)

HADB data type

Retrieval result

Return value

ARRAY

Null value

null

Other

Array object that stores the retrieval result

CHAR

VARCHAR

STRING

Null value

null

Other

String object created from retrieval result

SMALLINT#2

Null value

null

Other

Short object created from the retrieval result

INTEGER#3

Null value

null

Other

Integer object created from retrieval result

BIGINT

Null value

null

Other

Long object created from retrieval result

DECIMAL

NUMERIC

Null value

null

Other

java.math.BigDecimal object created from retrieval result

REAL

Null value

null

Other

Float object created from the retrieval result

DOUBLE PRECISION

FLOAT

Null value

null

Other

Double object created from retrieval result

DATE

Null value

null

Other

An object of the class specified in type created from retrieval result

TIME

Null value

null

Other

java.sql.Time object created from retrieval result

TIMESTAMP WITHOUT TIME ZONE

Null value

null

Other

An object of the class specified in type created from retrieval result

TIMESTAMP WITH TIME ZONE

Null value

null

Other

An object of the class specified in type created from retrieval result

BINARY

VARBINARY

Null value

null

Other

Retrieval result

UUID

Null value

null

Other

java.util.UUID object created from retrieval result

ROW

Non-null value#1

Retrieval result

BOOLEAN

Null value

null

Other

Boolean object created from retrieval result

#1

A retrieval result cannot be a null value.

#2

If the integer data type format is in legacy format, the Integer object is returned.

#3

If the integer data type format is in legacy format, the Long object is returned.

(5) Exceptions

The JDBC driver throws an SQLException in the following cases: