Collection Contents Index Inserting, updating, and deleting Java objects Comparing Java fields and objects pdf/chap17.pdf

User's Guide
   PART 3. Java in the Database
     CHAPTER 17. Using Java in the Database       

Querying Java objects


You may wish to retrieve a Java column value in either of the following ways:

Retrieving the entire object 

From SQL, you can create a variable of the appropriate type, and select the value from the object into that variable. However, the obvious place in which you may wish to make use of the entire object is in a Java application.

You can retrieve an object into a server-side Java class by using the getObject method of the ResultSet of a query. You can also retrieve an object to a client-side Java application, although the method is more complicated.

For Info     For a description of retrieving objects using JDBC, see Queries using JDBC.

Retrieving fields of the object 

Individual fields of an object have data types that correspond to SQL data types, using the SQL to Java data type mapping described in Java / SQL data type conversion.

For Info     For information on using objects in the WHERE clause and other issues in comparing objects, see Comparing Java fields and objects.

The results of SELECT column-name 

You can list the column name in a query select list, as in the following query:

SELECT JProd
FROM jdba.product

For Info    When you do this, you do not retrieve the object from each column. Instead, the returned value of the object's toString method is returned. For the Product class, the toString method lists, in one string, the size, name, and unit price of the object. The results of the query are as follows:

JProd

Small Tee Shirt: 9.00

Medium Tee Shirt: 14.00

One size fits all Tee Shirt: 14.00

One size fits all Baseball Cap: 9.00

One size fits all Baseball Cap: 10.00

One size fits all Visor: 7.00

One size fits all Visor: 7.00

Large Sweatshirt: 24.00

Large Sweatshirt: 24.00

Medium Shorts: 15.00


Collection Contents Index Inserting, updating, and deleting Java objects Comparing Java fields and objects pdf/chap17.pdf