Language:EN
Pages: 5
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
types pass the struct person the member self varia

Types pass the struct person the member self variable cstmt

An ArrayDescriptor object for the desired collection type

conn

// now create the Array
Array identifiers =
new oracle.sql.ARRAY(identifiersAD, conn, identifiersStructs );

// update the person Struct
personAttributes[6] = identifiers;

15.4.1 Retrieving a Reference

To retrieve a reference from a database, use the ref( ) database function. Do you remember how you used the value( ) function? Well, you use the ref( ) database function the same way. You use it in a SELECT statement, passing it an alias for a table name. For example, to select a reference to an object row in person_ot, use the following SQL statement:

15.4.2 Materializing Object Values Using a Ref

If you have a reference to a database row object in a Ref object, retrieving the database object is simple when using the oracle.sql.REF method getValue( ). All that is required is to cast the java.sql.Ref to an oracle.sql.REF in order to call the function:

((oracle.sql.REF)personRef).setValue(person);

There's no need for a SQL statement to update an object when you use a reference, because the REF interface uses the reference, which is a locator, to update the object directly. This is similar to how BLOB and CLOB objects can be updated via their locators.

In this example, we use the ref( ) database function to get the reference for the object rows in person_ot and then compare them to the reference we set in the DELETE statement with the setObject( ) method.

Now that you've seen how to insert, select, update, and delete row objects in a detailed, step-by-step fashion using the Struct, Array, and Ref interfaces, let's take a look at how to execute database object methods.

, parameter_n IN data_type] )
which breaks down as:
user_defined_type
A database user-defined data type or object
method_name
The name of a member method for the user-defined data type
self
An object retrieved from the database -- in our case, a Struct object -- upon which the member method is executed
parameter_1
The first parameter for the member method
parameter_n
The nth parameter for the member method
data_type
A SQL built-in or user-defined data type

For example, type person_typ has a member function get_age( ) that returns a person's current age. The function get_age( ) has the following signature:
get_age return number
To execute the function, call it as a stored procedure:
person_typ.get_age(self)
Pass a Struct object that represents the object you retrieved from the database as the person_typself parameter. For example:
Statement stmt = conn.createStatement( );
ResultSet rslt = stmt.executeQuery("select value(p) from person_ot p");

Example 15-1 puts all the concepts and short examples we've seen in this chapter into one cohesive example. Here's the big picture: the TestStruct program starts by cleaning up any rows left over from a prior execution. Then it adds a person and a location and ties them together with a person_location entry so that there are foreign key constraints on the person and location objects. Next, the program modifies the person object using both the
PreparedStatement object's setObject( ) method and the oracle.sql.REF object's setValue( ) method. Finally, the program selects the person object and displays its contents.

Since the person object has a collection for identifiers, the example exercises not only oracle.sql.STRUCT, but also oracle.sql.ARRAY. Let's continue by examining the TestStruct program in detail.

}

public static void main(String[] args) throws Exception {
new TestStruct().process( );
}

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Mrs. Eve Shanny

PageId: DOCFD5DA63