Oracle8i JDBC Developer's Guide and Reference Release 2 (8.1.6) A81354-01 |
|
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.
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:
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.sql.*
datatype classes for ROWIDs and REF CURSOR
types
oracle.sql.*
datatype support for BLOBs, CLOBs, and BFILEs
oracle.sql.*
datatype support for composite data structures (Oracle objects) in the database
oracle.sql.*
datatype support for object references
oracle.sql.*
datatype support for collections (VARRAYs and nested tables)
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:
oracle.sql.*
types)
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.
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.
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:
CORPORATE.EMPLOYEE
, the type name must be quoted.
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.
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.