DB2 Version 10.1 for Linux, UNIX, and Windows

Supported SQL data types in Java routines

Java™ programming language data types must be used in Java source code to store SQL data type values according to the JDBC and SQLJ application programming interface specification. The DB2® Driver for JDBC and SQLJ converts the data exchanged between Java source code and a DB2 database according to specific data type mappings.

The data mappings are valid for:
  • Java database applications
  • Java routines defined as and implemented using PARAMETER STYLE JAVA
The Java data types that map to SQL data types are as follows:
Table 1. SQL Data Types Mapped to Java Declarations
SQL Column Type Java Data Type SQL Column Type Description
SMALLINT
(500 or 501)
short, boolean 16-bit, signed integer
INTEGER
(496 or 497)
int 32-bit, signed integer

BIGINT1 (492 or 493)

long 64-bit, signed integer
REAL
(480 or 481)
float Single precision floating point
DOUBLE
(480 or 481)
double Double precision floating point
DECIMAL(p,s)
(484 or 485)
java.math.BigDecimal Packed decimal
CHAR(n)
(452 or 453)
java.lang.String Fixed-length character string of length n where n is from 1 to 254
CHAR(n)
FOR BIT DATA
byte[] Fixed-length character string of length n where n is from 1 to 254
VARCHAR(n)
(448 or 449)
java.lang.String Variable-length character string
VARCHAR(n)
FOR BIT DATA
byte[] Variable-length character string
LONG VARCHAR
(456 or 457)
java.lang.String Long variable-length character string
LONG VARCHAR
FOR BIT DATA
byte[] Long variable-length character string
BLOB(n)
(404 or 405)
java.sql.Blob Large object variable-length binary string
CLOB(n)
(408 or 409)
java.sql.Clob Large object variable-length character string
DBCLOB(n)
(412 or 413)
java.sql.Clob Large object variable-length double-byte character string
DATE
(384 or 385)
java.sql.Date 10-byte character string
TIME
(388 or 389)
java.sql.Time 8-byte character string
TIMESTAMP
(392 or 393)
java.sql.Timestamp The character string can be from 19 - 32 bytes in length depending on the number of fractional seconds specified.

The fractional seconds of the TIMESTAMP data type can be optionally specified with 0-12 digits of timestamp precision.

When a timestamp value is assigned to a timestamp variable with a different number of fractional seconds, the value is either truncated or padded with zeros to match the format of the variable.

GRAPHIC(n)
(468 or 469)
java.lang.String Fixed-length double-byte character string
VARGRAPHIC(n)
(464 or 465)
java.lang.String Non-null-terminated varying double-byte character string with 2-byte string length indicator
LONGVARGRAPHIC
(472 or 473)
java.lang.String Non-null-terminated varying double-byte character string with 2-byte string length indicator
XML(n)
(408 or 409)
java.sql.Clob The XML data type is represented in the same way as a CLOB data type; that is as a large object variable-length character string
ARRAY java.sql.Array An array of SQL data.
Note:
  1. For Java applications connected from a DB2 Universal Database™ Version 8.1 client to a DB2 Universal Database Version 7.1 (or 7.2) server, note the following: when the getObject() method is used to retrieve a BIGINT value, a java.math.BigDecimal object is returned.
  2. Parameters of an SQL array data type are mapped to class com.ibm.db2.ARRAY.
  3. LONG VARCHAR, LONG VARGRAPHIC, XML, REFERENCE, UDT and ARRAY are not supported for the ARRAY data type.