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

## Support Features of the Oracle Extensions

The Oracle extensions to JDBC include a number of features that enhance your ability to work with Oracle databases. Among these are support for Oracle datatypes, Oracle objects, and specific schema naming.

### Support for Oracle Datatypes

A key feature of the Oracle JDBC extensions is the type support in the `oracle.sql` package. This package includes classes that map to all the Oracle SQL datatypes, acting as wrappers for raw SQL data. This functionality provides two significant advantages in manipulating SQL data:

- Accessing data directly in SQL format is more efficient than first converting it to Java format.

- Performing mathematical manipulations of the data directly in SQL format avoids the loss of precision that occurs in converting between SQL and Java formats.

Once manipulations are complete and it is time to output the information, each of the `oracle.sql.*` type support classes has all the necessary methods to convert data to appropriate Java formats. For a more detailed description of these general issues, see "Package oracle.sql".

See the following for more information on specific `oracle.sql.*` datatype classes:

- "Oracle Type Extensions" for information on the `oracle.sql.*` datatype classes for ROWIDs and `REF CURSOR` types

- Chapter 7, "Working with LOBs and BFILEs" for information on `oracle.sql.*` datatype support for BLOBs, CLOBs, and BFILEs

- Chapter 8, "Working with Oracle Object Types" for information on `oracle.sql.*` datatype support for composite data structures (Oracle objects) in the database

- Chapter 9, "Working with Oracle Object References" for information on `oracle.sql.*` datatype support for object references

- Chapter 10, "Working with Oracle Collections" for information on `oracle.sql.*` datatype support for collections (VARRAYs and nested tables)

### Support for Oracle Objects

Oracle8i supports the use of structured objects in the database, where an object datatype is a user-defined type with nested attributes. For example, a user application could define an `Employee` object type, where each `Employee` object has a `firstname` attribute (a character string), a `lastname` attribute (another character string), and an `employeenumber` attribute (integer).

Oracle's JDBC implementation supports Oracle object datatypes. When you work with Oracle object datatypes in a Java application, you must consider the following:

- how to map between Oracle object datatypes and Java classes

- how to store Oracle object attributes in corresponding Java objects (they can be stored in standard Java types or in `oracle.sql.*` types)

- how to convert attribute data between SQL and Java formats

- how to access data

Oracle objects can be mapped either to the weak `java.sql.Struct` or `oracle.sql.STRUCT` types or to strongly typed customized classes. These strong types are referred to as custom Java classes, must implement either the standard `java.sql.SQLData` interface or the Oracle extension `oracle.sql.CustomDatum` interface, and are described in detail in Chapter 8, "Working with Oracle Object Types". Each interface specifies methods to convert data between SQL and Java.

To create custom Java classes to correspond to your Oracle objects, Oracle recommends that you use the Oracle8i JPublisher utility to create the classes. To do this, you must define attributes according to how you want to store the data. JPublisher performs this task seamlessly with command-line options and can generate either `SQLData` or `CustomDatum` implementations.

For `SQLData` implementations, a type map defines the correspondence between Oracle object datatypes and Java classes. Type maps are objects of a special Java class that specify which Java class corresponds to each Oracle object datatype. Oracle JDBC uses these type maps to determine which Java class to instantiate and populate when it retrieves Oracle object data from a result set.

Note: Oracle recommends using the `CustomDatum` interface, instead of the `SQLData` interface, in situations where portability is not a concern. `CustomDatum` works more easily and flexibly in conjunction with other features of the Oracle Java platform offerings.

JPublisher automatically defines `get` methods of the custom Java classes, which retrieve data into your Java application. For more information on the JPublisher utility, see the Oracle8i JPublisher User's Guide.

Chapter 8, "Working with Oracle Object Types" describes Oracle JDBC support for Oracle objects.

### Support for Schema Naming

Oracle JDBC classes have the ability to accept and return fully qualified schema names. A fully qualified schema name has this syntax:

    {[schema_name].}[sql_type_name]

Where `schema_name` is the name of the schema and `sql_type_name` is the SQL type name of the object. Notice that the `schema_name` and the `sql_type_name` is separated by a dot (".").

To specify an object type in JDBC, you use its fully qualified name (that is, a schema name and SQL type name). It is not necessary to enter a schema name if the type name is in current naming space (that is, the current schema). Schema naming follows these rules:

- Both the schema name and the type name may or may not be quoted. However, if the SQL type name has a dot in it, such as `CORPORATE.EMPLOYEE`, the type name must be quoted.

- The JDBC driver looks for the first unquoted dot in the object's name and uses the string before the dot as the schema name and the string following the dot as the type name. If no dot is found, the JDBC driver takes the current schema as default. That is, you can specify only the type name (without indicating a schema) instead of specifying the fully qualified name if the object type name belongs to the current schema. This also explains why you must quote the type name if the type name has a dot in it.

  For example, assume that user Scott creates a type called `person.address` and then wants to use it in his session. Scott might want to skip the schema name and pass in `person.address` to the JDBC driver. In this case, if `person.address` is not quoted, then the dot will be detected, and the JDBC driver will mistakenly interpret `person` as the schema name and `address` as the type name.

- JDBC passes the object type name string to the database unchanged. That is, the JDBC driver will not change the character case even if it is quoted.

  For example, if `ScOtT.PersonType` is passed to the JDBC driver as an object type name, the JDBC driver will pass the string to the database unchanged. As another example, if there is white space between characters in the type name string, then the JDBC driver will not remove the white space.

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