Using the SQLData interface

To implement a complete UDT in Java™ code, you must supply a set of data-formatting methods that convert to and from the various representations of the data type. These methods perform input and output operations for the data type such as converting text input to the internal structure that the database server uses.

About this task

All the database server I/O functions manipulate data formats that can be represented as Java streams. The streams encapsulate the data and implement methods needed to parse the source format or write the destination format.

To implement an opaque UDT and use the default data-translation I/O methods:

Procedure

  1. Supply the HCL OneDB™ JDBC Driver SQLData interface: readSQL(), writeSQL(), and getSQLTypeName() methods.
  2. Create the SQL routine and cast definitions for the I/O functions by calling sqlj.registerJUDTfuncs(varchar(255)), where the varchar argument is the SQL name of the type you are registering.
    For example, after creating the UDT Record3 with the following statements:
    create opaque type Record3 (internallength = variable,
       alignment = 8, maxlen = 2048, cannothash );
    grant usage on type Record3 to public;
    execute procedure setUDTExtName("Record3",
       "informix.testclasses.jlm.udt.Record3");
    You could create the default casts and I/O functions with the following statement:
    execute procedure registerJUDTfuncs(“Record3”); 

Results

The readSQL() method converts a database type to a Java object and the writeSQL() method converts a Java object to the database type. The system supplies the appropriate stream type at run time.

You can back out default I/O functions and casts by calling sqlj.unregisterJUDTfuncs(varchar(255)), where the varchar argument is the SQL name of the type, as the following example shows:
execute procedure unregisterJUDTfuncs(“Record3”);