|
A distinct type can map to the underlying base type or to a user-defined Java object. For example, a distinct type of int can map to int or to a Java object that encapsulates the data representation. This Java object must implement the java.sql.SQLData interface. You must provide a custom type map as described in Mapping Data Types to map this Java object to the corresponding SQL type name.
When an SQLData object inserts data into a distinct type column and getSQLTypeName() returns the name of the distinct type, Informix JDBC Driver uses the type information to verify that the data provided matches the data the database server expects. The driver asks the database server for the type information each time.
However, you can set an environment variable in the database URL, ENABLE_CACHE_TYPE=1, so the driver caches the type information the first time it is retrieved. In this case, Informix JDBC Driver asks the cache for the type information before requesting the data from the database server.
A distinct type can map to either the underlying base type or to a user-defined Java object that implements the SQLData interface. Here is the SQL statement that defines the distinct type:
Here is an example of mapping to the base type:
When you map to the underlying type, Informix JDBC Driver maps to the underlying type on the client side, because the database server provides implicit casting between the underlying type and the distinct type.
You can also map distinct types to Java objects that implement the SQLData interface. Here is the SQL statement that defines the distinct type:
Here is the rest of the example:
In this case, you use the setObject() method instead of the setBigDecimal() method to insert data.
You can fetch a distinct type as its underlying base type or as a Java object, if the mapping is defined in a custom type map. Using the previous example, you can fetch the data as a Java object as in the following example:
The following methods are not supported for distinct types: