User-defined Data Types

This chapter describes how tbJDBC processes user-defined data types.

The JDBC standard provides the java.sql.Array and java.sql.Struct interfaces to support user-defined data types.

  • An array type is used to collect and save the same type of values.

  • A struct type is used to collect and save multiple types of values.

Array Type

tbJDBC provides the com.tmax.tibero.jdbc.TbArray class which implements the java.sql.Array interface.

Declaring Arrays

Declare an array as follows:

create or replace type t_varr    is varray(16)     of varchar2(128);

create or replace type t_tbl     is table          of varchar2(128);

Using Arrays as Input Arguments

An array object can be sent to a PSM procedure as an input argument as follows:

  1. Create an array object by using the Connection object.

  1. Bind the array object to a procedure.

An array object can be sent to a PSM procedure by using CallableStatement.setObject().

The following example creates an array object and sends it to a PSM procedure as an input argument.

Using Arrays as Output Arguments

An array object can be received from a PSM procedure as an output argument as follows:

  1. Call a procedure through out binding. Then, the procedure returns an array object.

  2. Receive the array object by using CallableStatement.getArray().

  3. Receive the values from the array object.

The following example receives an array object from a procedure as an output argument. The p_out_t_varr procedure returns 16 string array values.


Struct Type

Unlike an array that saves a built-in type of values, a struct saves multiple types of values. tbJDBC provides the com.tmax.tibero.jdbc.TbStruct class which implements the java.sql.Struct interface.

Declaring Struct Data Type

Declare a record (struct) by declaring a package as follows:

Using Structs as Input Arguments

A struct object can be sent to a PSM procedure as an input argument as follows:

  1. Create a struct object by using the Connection object.

  1. Bind the struct object to a procedure.

A struct object can be sent to a PSM procedure by using CallableStatement.setObject().

The following example passes a struct object as an input argument. The print_obj procedure receives and processes a struct object.

Using Structs as Output Arguments

A struct object can be received from a PSM procedure as an output argument as follows:

  1. Call a procedure through out binding. Then, the procedure returns a struct object.

  2. Receive the struct object by using CallableStatement.getStruct().

  3. Receive the values from the struct object.

The following example receives a struct object from a procedure as an output argument. The p_out_t_rec procedure returns NUMBER, VARCHAR, and DATE types of record objects.


Sample Code with Arrays and Structs

The following is sample procedure code to create arrays and structs.

Last updated