The Struct interface

The JDBC documentation does not specify that Struct objects can be parameters to the PreparedStatement.setObject() method. However, HCL OneDB™ JDBC Driver can handle any object passed by the PreparedStatement.setObject() or ResultSet.getObject() method that implements the java.sql.Struct interface.

You must use the Struct interface to access unnamed rows.

You do not need to create your own class to implement the java.sql.Struct interface. However, you must perform a fetch to retrieve the ROW data and type information before you can insert or update the ROW data. HCL OneDB JDBC Driver automatically calls the getSQLTypeName() method, which returns the type name for a named row or the row definition for an unnamed row.

If you create your own class to implement the Struct interface, the class you create must implement all the java.sql.Struct methods, including the getSQLTypeName() method. You can choose what the getSQLTypeName() method returns.

Although you must return the row definition for unnamed rows, you can return either the row name or the row definition for named rows. Each has advantages:
  • Row definition. The driver does not need to query the database server for the type information. In addition, the row definition returned does not have to match the named row definition exactly, because the database server provides casting, if needed. This is useful if you want to use strings to insert into an opaque type in a row, for example.
  • Row name. If a user-defined routine takes a named row as a parameter, the signature has to match, so you must pass in a named row.

    For more information about user-defined routines, see the following publications: HCL® J/Foundation Developer's Guide (for information specific to Java™); HCL OneDB User-Defined Routines and Data Types Developer's Guide and HCL OneDB Guide to SQL: Reference (both for general information about user-defined routines); and HCL OneDB Guide to SQL: Syntax (for the syntax to create and invoke user-defined routines).

Important: If you use the Struct interface for a named row and provide type-mapping information for the named row, a ClassCastException message is generated when the ResultSet.getObject() method is called, because Java cannot cast between an SQLData object and a Struct object.