informix
Informix JDBC Driver Programmer's Guide
Manipulating Informix Data Types

Mapping Data Types

This section discusses mapping issues between data types defined in a Java program and the data types supported by the Informix database server. In particular, it covers the following topics:

Mapping Between Informix and JDBC Data Types

Since there are variations between the SQL data types supported by each database vendor, the JDBC API defines a set of generic SQL data types in the class java.sql.Types. Use these JDBC API data types to reference generic SQL types in your Java programs that use the JDBC API to connect to Informix databases.

The following table shows the Informix data type to which each JDBC API data type maps.

JDBC API Data Type Informix Data Type
BIGINT INT8
BINARY BYTE
BIT Not supported
CHAR CHAR(n)
DATE DATE
DECIMAL DECIMAL
DOUBLE FLOAT
FLOAT SMALLFLOAT
INTEGER INTEGER
LONGVARBINARY BYTE
LONGVARCHAR TEXT
NUMERIC DECIMAL
REAL SMALLFLOAT
SMALLINT SMALLINT
TIME DATETIME
TIMESTAMP DATETIME
TINYINT SMALLINT
VARBINARY BYTE
VARCHAR VARCHAR(m,r)

The LONGVARBINARY and LONGVARCHAR JDBC types can also map to Informix BLOB and CLOB types, respectively.

Important: Informix JDBC Driver maps java.sql.Timestamp to the Informix type datetime year to fraction(5) and java.sql.Time to the Informix type datetime hour to second. Informix datetime types are very restrictive and are not interchangeable. If you attempt to map java.sql.Time to datetime year to fraction(5) or java.sql.Timestamp to datetime hour to second, you might get an error from the Informix database server. Any other datetime qualifiers are not supported.

Important: The Ref type is not supported by Informix servers.

The following table lists mappings between the extended data types supported in Informix Dynamic Server with Universal Data Option and the corresponding Java and JDBC types.

JDBC Type Java Object Type Informix Type
java.sql.Types.OTHER java.sql.Types.SMALLINT boolean smallint boolean IfxTypes.IFX_TYPE_BOOL
java.sql.Types.LONGVARCHAR java.sql.String java.io.inputStream lvarchar IfxTypes.IFX_TYPE_LVARCHAR
java.sql.Types.JAVA_OBJECT java.sql.SQLData opaque type IfxTypes.IFX_TYPE_UDTFIXED IfxTypes.IFX_TYPE_UDTVAR
java.sql.Types.LONGVARBINARY java.sql.Types.BLOB java.sql.Blob java.io.inputStream byte[] BLOB IfxTypes.IFX_TYPE_BLOB
java.sql.Types.LONGVARCHAR java.sql.Types.CLOB java.sql.Clob java.io.inputStream java.lang.String CLOB IfxTypes.IFX_TYPE_CLOB
java.sql.Types.LONGVARBINARY java.sql.Types.BLOB java.io.inputStream java.sql.Blob byte[] byte IfxTypes.IFX_TYPE_BYTE
java.sql.Types.LONGVARCHAR java.sql.Types.CLOB java.io.InputStream java.sql.Clob java.sql.String text IfxTypes.IFX_TYPE_TEXT
java.sql.Types.JAVA_OBJECT java.sql.Types.STRUCT java.sql.SQLData java.sql.Struct named row IfxTypes.IFX_TYPE_ROW
java.sql.Types.STRUCT java.sql.Struct unnamed row IfxTypes.IFX_TYPE_ROW
java.sql.Types.ARRAY java.sql.Types.OTHER java.sql.Array java.util.LinkedList java.util.HashSet java.util.TreeSet set, multiset IfxTypes.IFX_TYPE_SET IfxTypes.IFX_TYPE_MULTISET
java.sql.Types.ARRAY java.sql.Types.OTHER java.sql.Array java.util.ArrayList java.util.LinkedList list IfxTypes.IFX_TYPE_LIST

A Java boolean object can map to a smallint object or an Informix boolean data type. Informix JDBC Driver attempts to map it according to the column type. However, in cases such as PreparedStatement host variables, Informix JDBC Driver cannot access the column types, so the mapping is somewhat limited. Refer to "PreparedStatement.setXXX() Extensions," next, for more details on data type mapping.

PreparedStatement.setXXX() Extensions

Informix Dynamic Server with Universal Data Option introduces many extended data types, such as BLOB, CLOB, boolean, lvarchar, and opaque types. As a result, there can be multiple mappings between a JDBC or Java data type and the corresponding Informix data type.

For example, you can use PreparedStatement.setAsciiStream() to insert into either a text column or a CLOB column. Similarly, you can also use PreparedStatement.setBinaryStream() to insert into a byte column or a BLOB column. Because the actual column information is not available to Informix JDBC Driver at all times, there can be ambiguity for the driver when it maps data types.

Normally, with INSERT, SELECT, or DELETE statements, the column information is available to the driver, so the driver can determine how the data can be sent to the database server.

However, when the data is referenced in an UPDATE statement or inside a WHERE clause, Informix JDBC Driver does not have access to the column information. In those cases, unless you use the extended methods listed next, the driver maps those data columns using the corresponding pre-Universal Data Option data types listed in the table on page 3-65. For the PreparedStatement.setAsciiStream() method, the driver tries to map to a text data type, and for the PreparedStatement.setBinaryStream() method, it tries to map to a byte data type.

To direct the driver to map to a certain data type (so there is no ambiguity in UPDATE statements and WHERE clauses), you can use extensions to the PreparedStatement.setXXX() methods. The Informix type must be the last parameter to the standard JDBC PreparedStatement.setXXX() interface.

The only data types that might have ambiguity are boolean, lvarchar, text, byte, BLOB, and CLOB. Refer to the data type mapping table on page 3-67 for more details on how these extended data types are mapped to Java and JDBC types.

The Mapping Extensions

The java.sql.PreparedStatement interface enables you to map to a specific Informix data type in cases that might result in ambiguity when you are inserting or updating data. The extensions are listed here. Each extension is followed by its full signature.

The setXXX Methods

IfmxPreparedStatement.setArray()

IfmxPreparedStatement.setAsciiStream()

IfmxPreparedStatement.setBigDecimal()

IfmxPreparedStatement.setBinaryStream()

IfmxPreparedStatement.setBlob()

IfmxPreparedStatement.setBoolean()

IfmxPreparedStatement.setByte()

IfmxPreparedStatement.setBytes()

IfmxPreparedStatement.setCharacterStream()

IfmxPreparedStatement.setClob()

IfmxPreparedStatement.setDate()

IfmxPreparedStatement.setDate()

IfmxPreparedStatement.setDouble()

IfmxPreparedStatement.setFloat()

IfmxPreparedStatement.setInt()

IfmxPreparedStatement.setLong()

IfmxPreparedStatement.setNull()

IfmxPreparedStatement.setShort()

IfmxPreparedStatement.setString()

IfmxPreparedStatement.setTime()

IfmxPreparedStatement.setTime()

IfmxPreparedStatement.setTimestamp()

IfmxPreparedStatement.setTimestamp()

The IfxSetObject Methods

IfmxPreparedStatement.IfxSetObject()

IfmxPreparedStatement.IfxSetObject()

For the IfmxPreparedStatement.IfxSetObject extension, you cannot simply overload the method signature with an added ifxType parameter, because such overloading creates method ambiguity. You must name the method to IfxSetObject instead.

To use the preceding methods, you must cast your PreparedStatement references to IfmxPreparedStatement:

The IfxTypes Class

The extended IfmxPreparedStatement methods require you to pass in the Informix data type to which you want to map. These types are part of the com.informix.lang.IfxTypes class. The following table shows the IfxTypes constants and the corresponding Informix data types.

IfxTypes Constant Informix Data Type
IfxTypes.IFX_TYPE_CHAR CHAR
IfxTypes.IFX_TYPE_SMALLINT SMINT
IfxTypes.IFX_TYPE_INT INT
IfxTypes.IFX_TYPE_FLOAT FLOAT
IfxTypes.IFX_TYPE_SMFLOAT SMFLOAT
IfxTypes.IFX_TYPE_DECIMAL DECIMAL
IfxTypes.IFX_TYPE_SERIAL SERIAL
IfxTypes.IFX_TYPE_DATE DATE
IfxTypes.IFX_TYPE_MONEY MONEY
IfxTypes.IFX_TYPE_NULL NULL
IfxTypes.IFX_TYPE_DATETIME DATETIME
IfxTypes.IFX_TYPE_BYTE BYTES
IfxTypes.IFX_TYPE_TEXT TEXT
IfxTypes.IFX_TYPE_VARCHAR VARCHAR
IfxTypes.IFX_TYPE_INTERVAL SQLINTERVAL
IfxTypes.IFX_TYPE_NCHAR NCHAR
IfxTypes.IFX_TYPE_NVCHAR NVCHAR
IfxTypes.IFX_TYPE_INT8 INT8
IfxTypes.IFX_TYPE_SERIAL8 SERIAL8
IfxTypes.IFX_TYPE_SET SQLSET
IfxTypes.IFX_TYPE_MULTISET SQLMULTISET
IfxTypes.IFX_TYPE_LIST SQLLIST
IfxTypes.IFX_TYPE_ROW SQLROW
IfxTypes.IFX_TYPE_COLLECTION COLLECTION
IfxTypes.IFX_TYPE_UDTVAR UDTVAR
IfxTypes.IFX_TYPE_UDTFIXED UDTFIXED
IfxTypes.IFX_TYPE_REFSER8 REFSER8
IfxTypes.IFX_TYPE_LVARCHAR LVARCHAR
IfxTypes.IFX_TYPE_SENDRECV SENDRECV
IfxTypes.IFX_TYPE_BOOL BOOL
IfxTypes.IFX_TYPE_IMPEXP IMPEXP
IfxTypes.IFX_TYPE_IMPEXPBIN IMPEXPBIN
IfxTypes.IFX_TYPE_CLOB CLOB
IfxTypes.IFX_TYPE_BLOB BLOB

Extension Summary

The following table lists the PreparedStatement.setXXX() methods that Informix JDBC Driver supports for nonextended data types. The top heading lists the standard JDBC API data types defined in the java.sql.Types class. These translate to specific Informix data types, as shown in the table on page 3-65. The table lists the setXXX() methods you can use to write data of a particular JDBC API data type.

An uppercase and bold X indicates the setXXX() method Informix recommends you use; a lowercase x indicates other setXXX() methods supported by Informix JDBC Driver.

setXXX() Method JDBC API Data Types from java.sql.Types
TINYINT SMALLINT INTEGER BIGINT REAL FLOAT DOUBLE DECIMAL NUMERIC BIT CHAR VARCHAR LONGVARCHAR BINARY VARBINARY LONGVARBINARY DATE TIME TIMESTAMP
setByte() X x x x x x x x x x1 x1
setShort() x X x x x x x x x x1 x1
setInt() x x X x x x x x x x1 x1
setLong() x x x X x x x x x x1 x1
setFloat() x x x x X x x x x x1 x1
setDouble() x x x x x X X x x x1 x1
setBigDecimal() x x x x x x x X X x x
setBoolean() x x x x x x x x x x x
setString() x x x x x x x x x X X x x x x x x x
setBytes() x X X x
setDate() x x X x
setTime() x x X x
setTimestamp() x x x X
setAsciiStream() X x x x
setUnicodeStream()
setBinaryStream() x x x X
setObject() x x x x x x x x x x x x2 x x x2 x x3 x
Notes: 1 The column value must match the type of setXXX() exactly, or an SQLException is raised. If the column value is not within the allowed value range, the setXXX() method raises an exception instead of converting the data type. For example, setByte(1) raises an SQLException if the value being written is 1000. 2 A byte array is written. 3 A Timestamp object is written instead of a Time object.

The setNull() method writes an SQL null value.

The following table lists the PreparedStatement.setXXX() methods that Informix JDBC Driver supports for the Informix extended data types, the mappings for which are shown in the table on page 3-67. The table lists the setXXX() methods you can use to write data of a particular extended data type.

An uppercase and bold X indicates the setXXX() method Informix recommends you use; a lowercase x indicates other setXXX() methods supported by Informix JDBC Driver. The table does not include setXXX() methods that you cannot use with any of the Informix extended data types.

setXXX() Method Informix Extended Data Types
BOOLEAN LVARCHAR Opaque types BLOB CLOB BYTE TEXT NAMED ROW UNNAMED ROW SET or MULTISET LIST
setByte() x x
setShort() x
setInt() x
setBoolean() X
setString() X x x
setBytes() x x
setAsciiStream() x x X
setBinaryStream() x x X
setObject() x x X x x x x X X x x
setArray() x x
setBlob() X
setClob() X

The setNull() method writes an SQL null value.

Supported ResultSet.getXXX() Methods

Use the ResultSet.getXXX() methods to transfer data from an Informix database to a Java program that uses the JDBC API to connect to an Informix database. For example, use the ResultSet.getString() method to get the data stored in a column of data type LVARCHAR.

Important: If you use an expression within an SQL statement-for example, SELECT mytype::LVARCHAR FROM mytab-you might not be able to use ResultSet.getXXX(columnName) to retrieve the value. Use ResultSet.getXXX(columnIndex) to retrieve the value instead.

The following table lists the ResultSet.getXXX() methods that Informix JDBC Driver supports for nonextended data types. The top heading lists the standard JDBC API data types defined in the java.sql.Types class. These translate to specific Informix data types, as shown in the table on page 3-65. The table lists the getXXX() methods you can use to retrieve data of a particular JDBC API data type.

An uppercase and bold X indicates the getXXX() method Informix recommends you use; a lowercase x indicates other getXXX() methods supported by Informix JDBC Driver.

getXXX() Method JDBC API Data Types from java.sql.Types
TINYINT SMALLINT INTEGER BIGINT REAL FLOAT DOUBLE DECIMAL NUMERIC BIT CHAR VARCHAR LONGVARCHAR BINARY VARBINARY LONGVARBINARY DATE TIME TIMESTAMP
getByte() X x x x x x x x x x1 x1
getShort() x X x x x x x x x x1 x1
getInt() x x X x x x x x x x1 x1
getLong() x x x X x x x x x x1 x1
getFloat() x x x x X x x x x x1 x1
getDouble() x x x x x X X x x x1 x1
getBigDecimal() x x x x x x x X X x x
getBoolean() x x x x x x x x x x x
getString() x x x x x x x x x X X x x x x x x x
getBytes() x X X x
getDate() x x X x
getTime() x x X x
getTimestamp() x x x X
getAsciiStream() X x x x
getUnicodeStream()
getBinaryStream() x x x X
getObject() x x x x x x x x x x x x2 x x x2 x x3 x
Notes: 1 The column value must match the type of getXXX() exactly, or an SQLException is raised. If the column value is not within the allowed value range, the getXXX() method raises an exception instead of converting the data type. For example, getByte(1) raises an SQLException if the column value is 1000. 2 A byte array is returned. 3 A Timestamp object is returned instead of a Time object.

The getXXX() methods return a null value if the retrieved column value is an SQL null value.

The following table lists the ResultSet.getXXX() methods that Informix JDBC Driver supports for the Informix extended data types, the mappings for which are shown in the table on page 3-67. The table lists the getXXX() methods you can use to retrieve data of a particular extended data type.

An uppercase and bold X indicates the getXXX() method Informix recommends you use; a lowercase x indicates other getXXX() methods supported by Informix JDBC Driver. The table does not include getXXX() methods that you cannot use with any of the Informix extended data types.

getXXX() Method Informix Extended Data Types
BOOLEAN LVARCHAR Opaque types BLOB CLOB BYTE TEXT NAMED ROW UNNAMED ROW SET or MULTISET LIST
getByte() x x
getShort() x
getInt() x
getBoolean() X
getString() X x x
getBytes() x x
getAsciiStream() x x X
getBinaryStream() x x X
getObject() x x X x x x x X X x x
getArray() x x
getBlob() X
getClob() X

The getXXX() methods return a null value if the retrieved column value is an SQL null value.


Informix JDBC Driver Programmer's Guide, Version 2.0
Copyright © 1999, Informix Software, Inc. All rights reserved