Hitachi

Hitachi Advanced Database Application Development Guide


8.5.43 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‒31: Combinations of HADB data types and Java data types

HADB data type

Java data type (value specified for <T>)

CHAR

String

VARCHAR

SMALLINT

Integer

INTEGER

Long

DECIMAL

java.math.BigDecimal

DOUBLE PRECISION

Double

DATE

java.sql.Date

TIME

java.sql.Time

TIMESTAMP

java.sql.Timestamp

BINARY

byte[]

VARBINARY

ROW

BOOLEAN#

Boolean

#

BOOLEAN type data will exist if the Resultset object was created from DatabaseMetadata.

(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‒32: Relationship between retrieval results and return values (getObject method)

HADB data type

Retrieval result

Return value

CHAR

VARCHAR

Null value

null

Other

String object created from retrieval result

SMALLINT

Null value

null

Other

Integer object created from retrieval result

INTEGER

Null value

null

Other

Long object created from retrieval result

DECIMAL

Null value

null

Other

java.math.BigDecimal object created from retrieval result

DOUBLE PRECISION

Null value

null

Other

Double object created from retrieval result

DATE

Null value

null

Other

java.sql.Date object created from retrieval result

TIME

Null value

null

Other

java.sql.Time object created from retrieval result

TIMESTAMP

Null value

null

Other

java.sql.Timestamp object created from retrieval result

BINARY

VARBINARY

Null value

null

Other

Retrieval result

ROW

Non-null value#1

Retrieval result

BOOLEAN#2

Null value

null

Other

Boolean object created from retrieval result

#1

A retrieval result cannot be a null value.

#2

BOOLEAN type data will exist if the Resultset object was created from DatabaseMetadata.

(5) Exceptions

The JDBC driver throws an SQLException in the following cases: