Advanced SQL3 data types give you a tremendous amount of flexibility. They are ideal for storing serialized Java™ objects, Extensible Markup Language (XML) documents, and multimedia data such as songs, product pictures, employee photographs, and movie clips. Java Database Connectivity (JDBC) 2.0 and higher provide support for working with these data types that are a part of the SQL99 standard.
The distinct type is a user-defined type that is based on a standard database type. For example, you can define a Social Security Number type, SSN, that is a CHAR(9) internally. The following SQL statement creates such a DISTINCT type.
CREATE DISTINCT TYPE CUJOSQL.SSN AS CHAR(9)
A distinct type always maps to a built-in data type. For more information on how and when to use distinct types in the context of SQL, consult the SQL reference manuals.
To use distinct types in JDBC, you access them the same way that you access an underlying type. The getUDTs method is a new method that allows you to query what distinct types are available on the system. Example: Distinct types program shows the following:
For more information, see the following example that shows various commons tasks you can perform by using distinct types:
There are three types of Large Objects (LOBs):
DBCLOBs are similar to CLOBs except for their internal storage representation of the character data. Because Java and JDBC externalize all character data as Unicode, there is only support in JDBC for CLOBs. DBCLOBs work interchangeable with the CLOB support from a JDBC perspective.
In many ways, a Binary Large Object (BLOB) column is similar to a CHAR FOR BIT DATA column that can be made large. You can store anything in these columns that can be represented as a stream of nontranslated bytes. Often, BLOB columns are used to store serialized Java objects, pictures, songs, and other binary data.
You can use BLOBs the same way you can use other standard database types. You can pass them to stored procedures, use them in prepared statements, and update them in result sets. The PreparedStatement class has a setBlob method for passing BLOBs to the database, and the ResultSet class adds a getBlob class for retrieving them from the database. A BLOB is represented in a Java program by a BLOB object that is a JDBC interface.
Refer to Write code that uses BLOBs for more information about how to use BLOBs.
Character Large Objects (CLOBs) are the character data complement to BLOBs. Instead of storing data in the database without translation, the data is stored in the database as text and is processed the same way as a CHAR column. As with BLOBs, JDBC 2.0 provides functions for dealing directly with CLOBs. The PreparedStatement interface contains a setClob method and the ResultSet interface contains a getClob method.
Refer to Write code that uses CLOBs for more information about how to use CLOBs.
Although BLOB and CLOB columns work like CHAR FOR BIT DATA and CHAR columns, this is conceptually how they work from an external user's perspective. Internally, they are different; because of the potentially enormous size of Large Object (LOB) columns, you typically work indirectly with data. For example, when a block of rows is fetched from the database, you do not move a block of LOBs to the ResultSet. You move pointers called LOB locators (that is, four-byte integers) into the ResultSet instead. However, it is not necessary to know about locators when working with LOBs in JDBC.
Datalinks are encapsulated values that contain a logical reference from the database to a file stored outside the database. Datalinks are represented and used from a JDBC perspective in two different ways, depending on whether you are using JDBC 2.0 or earlier, or you are using JDBC 3.0 or later.
Refer to Write code that uses Datalinks for more information about how to use Datalinks.
There are other SQL3 data types that have been defined and for which the JDBC API provides support. These are ARRAY, REF, and STRUCT. Presently, iSeries™ servers do not support these types. Therefore, the JDBC driver does not provide any form of support for them.