Skip to main content

DB2 Type Support

Foundations JDBC provides support for IBM DB2's type system, including DECFLOAT, double-byte character types (GRAPHIC/VARGRAPHIC/DBCLOB), XML, and ROWID.

Integer Types

DB2 TypeJava TypeNotes
SMALLINTShort16-bit integer
INTEGER / INTInteger32-bit integer
BIGINTLong64-bit integer
val smallType: Db2Type<Short> = Db2Types.smallint
val intType: Db2Type<Int> = Db2Types.integer
val bigType: Db2Type<Long> = Db2Types.bigint

Fixed-Point Types

DB2 TypeJava TypeNotes
DECIMAL / NUMERICBigDecimalExact numeric
DECIMAL(p,s)BigDecimalWith precision and scale
DECFLOATBigDecimalDB2-specific decimal floating point (16 or 34 digits)
val decType: Db2Type<BigDecimal> = Db2Types.decimal
val preciseType: Db2Type<BigDecimal> = Db2Types.decimal(10, 2)
val decfloatType: Db2Type<BigDecimal> = Db2Types.decfloat
val decfloat16: Db2Type<BigDecimal> = Db2Types.decfloat(16)

Floating-Point Types

DB2 TypeJava TypeNotes
REALFloatSingle precision
DOUBLE / FLOATDoubleDouble precision
val realType: Db2Type<Float> = Db2Types.real
val doubleType: Db2Type<Double> = Db2Types.double_

Boolean

DB2 TypeJava TypeNotes
BOOLEANBooleanNative since DB2 11.1
val boolType: Db2Type<Boolean> = Db2Types.boolean_

String Types (Single-Byte)

DB2 TypeJava TypeNotes
CHAR / CHARACTERStringFixed-length
CHAR(n)StringFixed-length with size
VARCHARStringVariable-length
VARCHAR(n)StringVariable-length with size
CLOBStringCharacter Large Object
val charType: Db2Type<String> = Db2Types.char_
val char10: Db2Type<String> = Db2Types.char_(10)
val varcharType: Db2Type<String> = Db2Types.varchar
val varchar255: Db2Type<String> = Db2Types.varchar(255)
val clobType: Db2Type<String> = Db2Types.clob

String Types (Double-Byte)

DB2 has dedicated types for double-byte character set (DBCS) strings.

DB2 TypeJava TypeNotes
GRAPHICStringFixed-length DBCS
GRAPHIC(n)StringFixed-length DBCS with size
VARGRAPHICStringVariable-length DBCS
VARGRAPHIC(n)StringVariable-length DBCS with size
DBCLOBStringDouble-byte CLOB
val graphicType: Db2Type<String> = Db2Types.graphic
val graphic10: Db2Type<String> = Db2Types.graphic(10)
val vargraphicType: Db2Type<String> = Db2Types.vargraphic
val dbclobType: Db2Type<String> = Db2Types.dbclob
note

DB2's JSON_OBJECT does not support GRAPHIC, VARGRAPHIC, or DBCLOB types. JSON serialization is not available for these types.

Binary Types

DB2 TypeJava TypeNotes
BINARYbyte[]Fixed-length binary
BINARY(n)byte[]Fixed-length binary with size
VARBINARYbyte[]Variable-length binary
VARBINARY(n)byte[]Variable-length binary with size
BLOBbyte[]Binary Large Object
val binaryType: Db2Type<ByteArray> = Db2Types.binary
val binary16: Db2Type<ByteArray> = Db2Types.binary(16)
val varbinaryType: Db2Type<ByteArray> = Db2Types.varbinary
val blobType: Db2Type<ByteArray> = Db2Types.blob
note

DB2's JSON_OBJECT does not support BINARY, VARBINARY, or BLOB types. JSON serialization is not available for these types.

Date/Time Types

DB2 TypeJava TypeNotes
DATELocalDateDate without time
TIMELocalTimeTime without date
TIMESTAMPLocalDateTimeTimestamp without timezone
TIMESTAMP(p)LocalDateTimeWith fractional seconds precision
val dateType: Db2Type<LocalDate> = Db2Types.date
val timeType: Db2Type<LocalTime> = Db2Types.time
val tsType: Db2Type<LocalDateTime> = Db2Types.timestamp
val ts6: Db2Type<LocalDateTime> = Db2Types.timestamp(6)

Special Types

DB2 TypeJava TypeNotes
XMLXmlNative XML support
ROWIDbyte[]DB2 row identifier
val xmlType: Db2Type<Xml> = Db2Types.xml
val rowidType: Db2Type<ByteArray> = Db2Types.rowid
note

DB2's JSON_OBJECT does not support the XML type. JSON serialization is not available for XML columns.

Nullable Types

Any type can be made nullable using .opt():

val notNull: Db2Type<Int> = Db2Types.integer
val nullable: Db2Type<Int?> = Db2Types.integer.opt()

Custom Domain Types

Wrap base types with custom Java types using transform:

// Wrapper type
data class ProductId(val value: Long)

// Create Db2Type from bigint
val productIdType: Db2Type<ProductId> = Db2Types.bigint.transform(::ProductId, ProductId::value)