How JDBC types map to Java types when using DB2

This section is an example of how JDBC drivers map Java(TM) types to JDBC types using the DB2(R) JDBC driver. (Refer to the DB2 JDBC driver documentation for a full description of the mapping.) Other database drivers may have different mappings depending on which SQL types the database supports.

Since the Java primitive types such as boolean and int are not subtypes of Object, there is a slightly different mapping from JDBC types to Java Object types for the getObject/setObject methods. Two tables are presented below: the first shows the normal mapping, and the second shows the getObject/setObject method mapping.

The mapping for String will normally be VARCHAR, but will turn into LONGVARCHAR if the given value exceeds the driver's limit on VARCHAR values. The same is true for values of type byte[], VARBINARY, and LONGVARBINARY.

Table 1. JDBC types mapped to Java types
JDBC type Java type
CHAR String
VARCHAR String
LONGVARCHAR String
NUMERIC java.math.BigDecimal
DECIMAL java.math.BigDecimal
BIT boolean
TINYINT byte
SMALLINT short
INTEGER int
BIGINT long
REAL float
FLOAT double
DOUBLE double
BINARY byte[]
VARBINARY byte[]
LONGVARBINARY byte[]
DATE java.sql.Date
TIME java.sql.Time
TIMESTAMP java.sql.Timestamp
Table 2. JDBC types mapped to Java Object types
JDBC type Java Object type
CHAR String
StringVARCHAR String
LONGVARCHAR String
NUMERIC java.math.BigDecimal
DECIMAL java.math.BigDecimal
BIT Boolean
TINYINT Integer
SMALLINT Integer
INTEGER Integer
BIGINT Long
REAL Float
FLOAT Double
DOUBLE Double
BINARY byte[]
VARBINARY byte[]
LONGVARBINARY byte[]
DATE java.sql.Date
TIME java.sql.Time
TIMESTAMP java.sql.Timestamp