How Java types map to JDBC types when using DB2

This section is an example of how JDBC drivers map JDBC types to Java(TM) 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 built-in types such as boolean and int are not subtypes of Object, there is a slightly different mapping from Java Object types to JDBC 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. Java types mapped to JDBC types
Java Type JDBC type
String VARCHAR or LONGVARCHAR
java.math.BigDecimal NUMERIC
boolean BIT
byte TINYINT
short SMALLINT
int INTEGER
long BIGINT
float REAL
double DOUBLE
byte[] VARBINARY or LONGVARBINARY
java.sql.Date DATE
java.sql.Time TIME
java.sql.Timestamp TIMESTAMP
Table 2. Java Object types mapped to JDBC types
Java Object type JDBC type
String VARCHAR or LONGVARCHAR
java.math.BigDecimal NUMERIC
Boolean BIT
Integer INTEGER
Long BIGINT
Float REAL
Double DOUBLE
byte[] VARBINARY or LONGVARBINARY
java.sql.Date DATE
java.sql.Time TIME
java.sql.Timestamp TIMESTAMP