Oracle8i JDBC Developer's Guide and Reference Release 3 (8.1.7) Part Number A83724-01 |
Library | Service | Contents | Index

## Oracle Extensions for Object References

Oracle supports the use of references (pointers) to Oracle database objects. Oracle JDBC provides support for object references as:

- columns in a SELECT-list

- `IN` or `OUT` bind variables

- attributes in an Oracle object

- elements in a collection (array) type object

In SQL, an object reference (`REF`) is strongly typed. For example, a reference to an `EMPLOYEE` object would be defined as an `EMPLOYEE REF`, not just a `REF`.

When you select an object reference in Oracle JDBC, be aware that you are retrieving only a pointer to an object, not the object itself. You have the choice of materializing the reference as a weakly typed `oracle.sql.REF` instance (or a `java.sql.Ref` instance for portability), or materializing it as an instance of a custom Java class that you have created in advance, which is strongly typed. Custom Java classes used for object references are referred to as custom reference classes in this manual and must implement the `oracle.sql.CustomDatum` interface.

The `oracle.sql.REF` class implements the standard `java.sql.Ref` interface (`oracle.jdbc2.Ref` under JDK 1.1.x).

You can retrieve a `REF` instance through a result set or callable statement object, and pass an updated `REF` instance back to the database through a prepared statement or callable statement object. The `REF` class includes functionality to get and set underlying object attribute values, and get the SQL base type name of the underlying object (for example, `EMPLOYEE`).

Custom reference classes include this same functionality, as well as having the advantage of being strongly typed. This can help you find coding errors during compilation that might not otherwise be discovered until runtime.

For more information about custom reference classes, see "Custom Reference Classes with JPublisher".

For a complete sample application using the REF class to access SQL object data, see "Weakly Typed Object References--StudentRef.java".

Notes: If you are using the `oracle.sql.CustomDatum` interface for custom object classes, you will presumably use `CustomDatum` for corresponding custom reference classes as well. If you are using the standard `java.sql.SQLData` interface for custom object classes, however, you can only use weak Java types for references (`java.sql.Ref` or `oracle.sql.REF`). The `SQLData` interface is for mapping SQL object types only. You cannot create `REF` objects in your JDBC application; you can only retrieve existing `REF` objects from the database. You cannot have a reference to an array, even though arrays, like objects, are structured types.

| Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index