Oracle8i JDBC Developer's Guide and Reference
Release 3 (8.1.7)

Part Number A83724-01


Solution Area



Go to previous page Go to beginning of chapter Go to next page

Describing an Object Type

Release 8.1.6 and higher includes new functionality to retrieve information about a structured object type regarding its attribute names and types. This is similar conceptually to retrieving information from a result set about its column names and types, and in fact uses an almost identical API.

Functionality for Getting Object Meta Data

The oracle.sql.StructDescriptor class, discussed earlier in "STRUCT Descriptors" and "Steps in Creating StructDescriptor and STRUCT Objects", now includes functionality to retrieve meta data about a structured object type.

The StructDescriptor class has a getMetaData() method with the same functionality as the standard getMetaData() method available in result set objects. It returns a set of attribute information such as attribute names and types. Call this method on a StructDescriptor object to get meta data about the Oracle object type that the StructDescriptor object describes. (Remember that each structured object type must have an associated StructDescriptor object.)

The signature of the StructDescriptor class getMetaData() method is the same as the signature specified for getMetaData() in the standard ResultSet interface:

However, this method actually returns an instance of oracle.jdbc.driver.StructMetaData, a class that supports structured object meta data in the same way that the standard java.sql.ResultSetMetaData interface specifies support for result set meta data.

The StuctMetaData class includes the following standard methods that are also specified by ResultSetMetaData:

As well as the following method, supported only by StructMetaData:

Steps for Retrieving Object Meta Data

Use the following steps to obtain meta data about a structured object type:

  1. Create or acquire a StructDescriptor instance that describes the relevant structured object type.

  2. Call the getMetaData() method on the StructDescriptor instance.

  3. Call the meta data getter methods as desired--getColumnName(), getColumnType(), and getColumnTypeName().


    If one of the structured object attributes is itself a structured object, repeat steps 1 through 3.  


The following method shows how to retrieve information about the attributes of a structured object type. This includes the initial step of creating a StructDescriptor instance.

// Print out the ADT's attribute names and types 
void getAttributeInfo (Connection conn, String type_name) throws SQLException 
  // get the type descriptor 
  StructDescriptor desc = StructDescriptor.createDescriptor (type_name, conn); 

  // get type meta data 
  ResultSetMetaData md = desc.getMetaData (); 

  // get # of attrs of this type 
  int numAttrs = desc.length (); 

  // temporary buffers 
  String attr_name; 
  int attr_type; 
  String attr_typeName; 

  System.out.println ("Attributes of "+type_name+" :"); 
  for (int i=0; i<numAttrs; i++) 
    attr_name = md.getColumnName (i+1); 
    attr_type = md.getColumnType (i+1); 
    System.out.println (" index"+(i+1)+" name="+attr_name+" type="+attr_type); 

    // drill down nested object 
    if (attrType == OracleTypes.STRUCT) 
      attr_typeName = md.getColumnTypeName (i+1); 

      // recursive calls to print out nested object meta data 
      getAttributeInfo (conn, attr_typeName); 

Go to previous page
Go to beginning of chapter
Go to next page
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.


Solution Area