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

## Accessing and Updating Object Values through an Object Reference

You can use the `REF` object `setValue()` method to update the value of an object in the database through an object reference. To do this, you must first retrieve the reference to the database object and create a Java object (if one does not already exist) that corresponds to the database object.

For example, you can use the code in the section "Retrieving and Passing an Object Reference" to retrieve the reference to a database `ADDRESS` object:

    ResultSet rs = stmt.executeQuery("SELECT col3 FROM PEOPLE");
    if (rs.next())
    {
       REF ref = rs.getREF(1);
       Address a = (Address)ref.getValue();
    }

Then, you can create a Java `Address` object (this example omits the content for the constructor of the `Address` class) that corresponds to the database `ADDRESS` object. Use the `setValue()` method of the `REF` class to set the value of the database object:

    Address addr = new Address(...);
    ref.setValue(addr);

Here, the `setValue()` method updates the database `ADDRESS` object immediately.

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