Oracle8i JDBC Developer's Guide and Reference
Release 8.1.5

A64685-01

Library

Product

Contents

Index

Prev  Chap Top Next

Oracle JDBC Packages and Classes

This section discusses the Java packages that support the Oracle JDBC extensions and the key classes that are included in these packages. This section has the following subsections:

You can refer to the Javadoc for more information about all of the classes mentioned in this section.

Classes of the oracle.jdbc2 Package

The oracle.jdbc2 package contains the Oracle implementation of the standard JDBC 2.0 interfaces. The JDBC 2.0 interfaces are part of the java.sql package included in the JDK 1.2. However, since the drivers do not currently support JDK 1.2, these interfaces have been made available to the Oracle 1.0.2 and 1.1.x drivers as the oracle.jdbc2 package. This package contains the JDBC 2.0 features of the JDK 1.2 java.sql package that the Oracle drivers support.

The following interfaces are implemented by oracle.sql.* type classes for JDBC 2.0-compliant Oracle type extensions. These interfaces are equivalent to the interfaces published by Sun Microsystems; the oracle.jdbc2 versions add no new features.

In addition, Oracle includes the following standard JDBC 2.0 interfaces for users employing the JDBC-standard SQLData interface to create Java classes that map to Oracle objects:

The SQLData interface is one of the two features you can use to support Oracle objects in Java. The other feature is the Oracle CustomDatum interface, contained in the oracle.sql package. See "Understanding the SQLData Interface" for more information about SQLData, SQLInput, and SQLOutput.


Note:

Oracle recommends using the CustomDatum interface instead of the SQLData interface. CustomDatum works more easily in conjunction with other features of the Oracle Java product offerings, such as the JPublisher utility (which can automatically generate CustomDatum classes corresponding to Oracle objects) and SQLJ.  


Classes of the oracle.sql Package

The oracle.sql package supports direct access to data in SQL format and consists primarily of classes that map to the Oracle SQL datatypes.

These classes provide Java mappings for the Oracle SQL types and are wrapper classes for the raw SQL data. Because data in an oracle.sql.* object remains in SQL format, no information is lost. For SQL primitive types, these classes simply wrap the SQL data. For SQL structured types (objects and arrays), they provide additional information such as conversion methods and details of structure.

Each of the Oracle datatype classes extends oracle.sql.Datum, a superclass that encapsulates functionality common to all of the datatypes. Some of the classes are for JDBC 2.0-compliant datatypes. These classes, as Table 4-1 indicates, implement standard JDBC 2.0 interfaces in the oracle.jdbc2 package, as well as extending oracle.sql.Datum.

Table 4-1 lists the oracle.sql datatype classes and their corresponding Oracle SQL types.

Table 4-1 Oracle Datatype Classes
Java Class
 
Oracle SQL Type (and Description)
and Interface Implemented if for JDBC 2.0
 

oracle.sql.STRUCT  

STRUCT (objects)
JDBC 2.0, implements oracle.jdbc2.Struct  

oracle.sql.REF  

REF (object references)
JDBC 2.0, implements oracle.jdbc2.Ref  

oracle.sql.ARRAY  

varray or nested table (collections)
JDBC 2.0, implements oracle.jdbc2.Array  

oracle.sql.BLOB  

BLOB (large binary objects)
JDBC 2.0, implements oracle.jdbc2.Blob  

oracle.sql.CLOB  

CLOB (large character objects)
JDBC 2.0, implements oracle.jdbc2.Clob  

oracle.sql.BFILE  

BFILE (external files)  

oracle.sql.CHAR  

CHAR, VARCHAR2  

oracle.sql.DATE  

DATE  

oracle.sql.NUMBER  

NUMBER  

oracle.sql.RAW  

RAW  

oracle.sql.ROWID  

ROWID (row identifiers)  

The following sections describe each class listed in Table 4-1. Additional details about use of the Oracle extended types (STRUCT, REF, ARRAY, BLOB, CLOB, BFILE, and ROWID) are described in "Working with LOBs", "Working with Oracle Object References", "Working with Arrays", and "Additional Type Extensions".


Notes:

  • Beware of possible confusion between the STRUCT class, used for objects only, and the general term structured objects, which often indicates either objects or collections. The ARRAY class supports collections, which can be either varrays or nested tables.

  • For information about retrieving data from a result set or callable statement object into oracle.sql.* types as opposed to Java types, see "Data Access and Manipulation: Oracle Types vs. Java Types".

  • The LONG, LONG RAW, or REF CURSOR SQL types have no oracle.sql.* classes. Use standard JDBC functionality for these types. For example, retrieve LONG or LONG RAW data as input streams using the standard JDBC methods getAsciStream(), getBinaryStream(), and getUnicodeStream(). Use getCursor() for REF CURSOR types.

 

In addition to the datatype classes, the oracle.sql package includes these support classes and interfaces:

Refer to the Javadoc for additional information about these classes. The rest of this section further describes the oracle.sql.* classes.

General oracle.sql Datatype Support

Each of the Oracle datatype classes provides, among other things, the following:

Refer to the Javadoc for additional information about these classes.

Class oracle.sql.STRUCT

For any given Oracle object type, if you do not specify a mapping to a Java class in your connection's type map, data from the object type will be materialized in Java in an instance of the oracle.sql.STRUCT class.

The STRUCT class implements the standard JDBC 2.0 oracle.jdbc2.Struct class and extends oracle.sql.Datum.

In the database, Oracle stores the raw bytes of object data in a linearized form. A STRUCT object is a wrapper for the raw bytes of an Oracle object and contains a "values" array of oracle.sql.Datum objects holding the attribute values in SQL format. The STRUCT object also contains the SQL type name of the Oracle object.

In most cases you will probably want to create a custom Java type definition class to map to your Oracle object, although using the STRUCT class may suffice in some cases (see "Using STRUCT Objects"). The attributes of a STRUCT can be materialized as java.lang.Object[] objects if you use the getAttributes() method, or as oracle.sql.Datum[] objects if you use the getOracleAttributes() method. The oracle.sql.* format gives you the same advantages as using oracle.sql.* datatype classes in general:

In some cases you might want to manually create a STRUCT object to pass it to a prepared statement or callable statement. To do this, you must also create a StructDescriptor object. For more information on creating a STRUCT object, see "Creating STRUCT Objects and Descriptors".

The STRUCT class includes the following methods:

Creating STRUCT Objects and Descriptors

To create an oracle.sql.STRUCT object, a STRUCT descriptor must first exist for the given Oracle object type. This descriptor is an object of the oracle.sql.StructDescriptor class.

A StructDescriptor describes a type of SQL structured object (Oracle object). Only one StructDescriptor is necessary for each Oracle object type.

The driver caches STRUCT descriptor objects to avoid recreating them if the type has already been encountered. The Oracle JDBC extensions provide a static createDescriptor() method that will either construct a new StructDescriptor object or return an existing one.

To create a StructDescriptor object, pass in a Java string parameter with the SQL type name of the Oracle object type and a connection object to the StructDescriptor.createDescriptor() method:

StructDescriptor structdesc = StructDescriptor.createDescriptor(sql_type_name, 
connection);

where sql_type_name is a Java string containing the name of the Oracle object type (such as EMPLOYEE) and connection is your connection object.

You can also call the StructDescriptor object if you need to create a new STRUCT object. To construct a new StructDescriptor object, pass in a Java string parameter with the SQL type name of the Oracle object type and your connection object:

StructDescriptor structdesc = new StructDescriptor(sql_type_name, connection);

To construct a STRUCT object, pass in the StructDescriptor, your connection object, and an array of Java objects containing the attributes you want the STRUCT to contain.

STRUCT struct = new STRUCT(structdesc, connection, attributes);

where structdesc is the StructDescriptor created previously, connection is your connection object, and attributes is an array of type java.lang.Object[].

Using StructDescriptor get Methods

A STRUCT descriptor can be referred to as a "type object." This means that it contains information about the type code and type name of the object type and how to convert to and from the given type. Remember, there should be only one StructDescriptor object for any one Oracle object type. You can then use that descriptor to create as many STRUCT objects as you need for that type.

The StructDescriptor class includes the getName() method to return the fully qualified SQL type name of the Oracle object (that is, in schema.sql_type_name format. For example, CORPORATE.EMPLOYEE)

Embedded Objects

The JDBC driver seamlessly handles embedded objects (STRUCT objects that are attributes of STRUCT objects) in the same way that it normally handles objects. When the JDBC driver retrieves an attribute that is an object, it follows the same rules of conversion, using the type map if it is available, or else using default mapping.

Class oracle.sql.REF

The oracle.sql.REF class is the generic class that supports Oracle object references. This class, as with all of the oracle.sql.* datatype classes, is a subclass of oracle.sql.Datum. It implements the standard JDBC 2.0 oracle.jdbc2.Ref interface.

Selecting a REF retrieves only a pointer to an object; it does not materialize the object. However, there are methods to accomplish this.

The oracle.sql.REF class includes the following methods:

The setREF() and setRef() methods of the OraclePreparedStatement and OracleCallableStatement classes support passing a REF object as an input parameter to a prepared statement. Similarly, the getREF() and getRef() methods of the OracleCallableStatement and OracleResultSet support passing a REF object as an output parameter.

You cannot create REF objects using JDBC.

For more information on how to use REF objects, see "Working with Oracle Object References".

Class oracle.sql.ARRAY

The oracle.sql.ARRAY class supports Oracle collections, either varrays or nested tables. If you select either a varray or nested table from the database, then the JDBC driver materializes it as an object of the ARRAY class; the structure of the data is equivalent in either case. The oracle.sql.ARRAY class extends oracle.sql.Datum (as do all of the oracle.sql.* classes) and implements oracle.jdbc2.Array, a standard JDBC 2.0 array interface.

You might want to manually create an ARRAY object to pass it to a prepared statement or callable statement, perhaps to insert into the database. This involves the use of ArrayDescriptor objects, which "Creating ARRAY Objects and Descriptors" describes.

The ARRAY class includes the following methods:

Creating ARRAY Objects and Descriptors

The setARRAY() method of the OraclePreparedStatement or OracleCallableStatement class supports passing an array as an input parameter to a prepared statement. You must first construct an array descriptor, which is an oracle.sql.ArrayDescriptor object, and then you must construct the oracle.sql.ARRAY object for the array you want to pass.

An ArrayDescriptor object describes the SQL type of an array; however, you need only one array descriptor for any one SQL type. You can reuse the same descriptor object to create multiple instances of an oracle.sql.Array object for the same array type.

Collections are strongly typed. Oracle supports only "named arrays", that is, an array given a SQL type name. For example, when you create an array with the CREATE TYPE statement:

CREATE TYPE num_varray AS varray(22) OF NUMBER(5,2); 

the SQL type name for the collection type is num_varray.


Note:

The name of the collection type has nothing to do with the type name of the elements. For example:

CREATE TYPE person AS object (c1 NUMBER(5), c2 VARCHAR2(30));

CREATE TYPE array_of_persons AS varray(10) OF person;

in the preceding statements, the SQL type name of the collection type is array_of_persons. The SQL type name of the elements of the collection is person.  


To construct an ArrayDescriptor object, pass the SQL type name of the collection type and your Connection object (which JDBC uses to go to the database to gather meta data) to the constructor.

ArrayDescriptor arraydesc = ArrayDescriptor.createDescriptor(sql_type_name, 
connection);

where sql_type_name is the type name of the array and connection is your Connection object.

To construct an ARRAY object, pass in the array descriptor, your connection object, and a Java object containing the individual elements you want the array to contain.

ARRAY array = new ARRAY(arraydesc, connection, elements);

where arraydesc is the array descriptor created previously, connection is your connection object, and elements is a Java array of objects. The two possibilities for the contents of elements are:

Using ArrayDescriptor get Methods

An array descriptor can be referred to as a type object, meaning it has information about the array's SQL type name, the type code of the array's elements and, if the array is a STRUCT, the type name of the elements. The array descriptor also contains the information on how to convert to and from the given type. You need only one array descriptor object for any one type, then you can use that descriptor to create as many arrays of that type as you want.

The ArrayDescriptor class has the following methods for retrieving an element's type code and type name:

Classes oracle.sql.BLOB, oracle.sql.CLOB, oracle.sql.BFILE

BLOBs, CLOBs, and BFILEs, all referred to as LOBs, are for data items that are too large to store directly in the database table. Instead, the database table stores a locator that points to the location of the actual data.

The oracle.sql package supports LOBs in several ways:

You can select a BLOB, CLOB, or BFILE locator from the database using a standard SELECT statement, but bear in mind that you are receiving only the locator, not the data itself. Additional steps are necessary to retrieve the data. This is described in "Working with LOBs".


Note:

The oracle.sql.CLOB class supports all character sets that the Oracle data server supports for CLOB types.  


The oracle.sql.BLOB class includes the following methods:

The oracle.sql.CLOB class includes the following methods:

The oracle.sql.BFILE class includes the following methods:

Class oracle.sql.CHAR

The CHAR class has special functionality for NLS conversion of character data. A key attribute of the CHAR class, and a parameter always passed in when a CHAR object is constructed, is the NLS character set used in presenting the character data. Without the character set being known, the bytes of data in the CHAR object are meaningless.

CHAR objects that the driver constructs and returns can be in the database character set, UTF-8, or ISO-Latin-1 (WE8ISO8859P1). CHAR objects which are Oracle8 objects, are returned in the database character set.

JDBC constructs and populates CHAR objects once character data has been read from the database. Additionally, you might want to construct a CHAR object yourself (to pass in to a prepared statement, for example).

When you construct a CHAR object, you must provide character set information to the CHAR object by way of an instance of the oracle.sql.CharacterSet class. Each instance of the CharacterSet class represents one of the NLS character sets that Oracle supports. A CharacterSet instance encapsulates methods and attributes of the character set, mainly involving functionality to convert to or from other character sets. You can find a complete list of the character sets that Oracle supports in the Oracle8i National Language Support Guide.

If you use a CHAR object based on a character set that Oracle does not support, then the JDBC driver will not be able to perform character set conversions with it. For example, you will not be able to use the CHAR object in an OraclePreparedStatement.setOracleObject() call.

Follow these general steps to construct a CHAR object:

  1. Create a CharacterSet instance by calling the static CharacterSet.make() method. This method is a factory for the character set class. It takes as input an integer OracleId, which corresponds to a character set that Oracle supports. For example:

    int oracleId = CharacterSet.JA16SJIS_CHARSET; // this is character set 832
    ...
    CharacterSet mycharset = CharacterSet.make(OracleId);
    
    

    Each character set that Oracle supports has a unique predefined OracleId. If you enter an invalid OracleId, an exception will not be thrown. Instead, when you try to use the character set, you will receive unpredictable results. For more information on character sets and character set IDs, see the Oracle8i National Language Support Guide.

  2. Construct a CHAR object. Pass to the constructor a string (or the bytes that represent the string) and the CharacterSet object that indicates how to interpret the bytes based on the character set. For example:

    String mystring = "teststring";
    ...
    CHAR mychar = new CHAR(teststring, mycharset);
    
    

    The CHAR class has multiple constructors: they can take a string, a byte array, or an object as input along with the CharacterSet object. In the case of a string, the string is converted to the character set indicated by the CharacterSet object before being placed into the CHAR object.

    Refer to the CHAR class Javadoc for more information.


    Notes:

    • The CharacterSet object cannot be null.

    • The CharacterSet class is an abstract class, therefore it has no constructor. The only way to create instances is through use of the make() method.

    • The server recognizes the special value CharacterSet.DEFAULT_CHARSET as the database character set. For the client, this value is not meaningful.

    • Oracle does not intend or recommend that users extend the CharacterSet class.

     

The CHAR class provides these methods for translating character data to strings:

The server (database) and the client (or application running on the client) can use different character sets. When you use the methods of this class to transfer data between the server and the client, the JDBC drivers must convert the data from the server character set to the client character set (or vice versa). To convert the data, the drivers use Oracle's National Language Support (NLS). For more information on how the JDBC drivers convert between character sets, see "Using NLS". For more information on NLS, see the Oracle8i National Language Support Guide.

Classes oracle.sql.DATE, oracle.sql.NUMBER, and oracle.sql.RAW

These classes map to primitive SQL datatypes, which are a part of standard JDBC. These classes provide conversions to and from their corresponding JDBC Java types. For more information, see the Javadoc.

Class oracle.sql.ROWID

This class supports Oracle ROWIDs, which are unique identifiers for rows in database tables. You can select a ROWID as you would select any column of data from the table. Note, however, that you cannot manually update ROWIDs; the Oracle database updates them automatically as appropriate.

The oracle.sql.ROWID class does not implement any noteworthy functionality beyond what is in the oracle.sql.Datum superclass. However, ROWID does provide a stringValue() method that overrides the stringValue() method in the oracle.sql.Datum class and returns the hexadecimal representation of the ROWID bytes.

For information about accessing ROWID data, see "Additional Oracle Extensions".

Classes of the oracle.jdbc.driver Package

The oracle.jdbc.driver package includes classes that add extended features to enable data access in oracle.sql format. In addition, these classes provide Oracle-specific extensions to allow access to raw SQL format data by using oracle.sql.* objects.

Table 4-2 lists key classes for connections, statements, and result sets in this package.

Table 4-2 Connection, Statement, and Result Set Classes
Class  Key Functionality  

OracleDriver  

implements java.sql.Driver  

OracleConnection  

methods to return Oracle statement objects; methods to set Oracle performance extensions for any statement executed in the current connection (implements java.sql.Connection)  

OracleStatement  

methods to set Oracle performance extensions for individual statement; superclass of OraclePreparedStatement and OracleCallableStatement (implements java.sql.Statement)  

OraclePreparedStatement  

set methods to bind oracle.sql.* types into a prepared statement (implements java.sql.PreparedStatement; extends OracleStatement)  

OracleCallableStatement  

get methods to retrieve data in oracle.sql format; set methods to bind oracle.sql.* types into a callable statement (inherited from OraclePreparedStatement) (implements java.sql.CallableStatement; extends PreparedStatement)  

OracleResultSet  

get methods to retrieve data in oracle.sql format (implements java.sql.ResultSet)  

OracleResultSetMetaData  

methods to get information about Oracle result sets (implements java.sql.ResultSetMetaData)  

The oracle.jdbc.driver package additionally includes:

The stream classes extend standard Java stream classes and read and write Oracle LOB, LONG, and LONG RAW data.

OracleTypes defines integer constants, which identify SQL types. For standard types, it uses the same values as the standard java.sql.Types. In addition, it adds constants for Oracle extended types.

The remainder of this section describes the classes of the oracle.jdbc.driver package. For more information about using these classes to access Oracle type extensions, see "Data Access and Manipulation: Oracle Types vs. Java Types".

Class oracle.jdbc.driver.OracleDriver

Use this class to register the Oracle JDBC drivers for use by your application. You can input a new instance of this class to the static registerDriver() method of the java.sql.DriverManager class so that your application can access and use the Oracle drivers. The registerDriver() method takes as input a "driver" class; that is, a class that implements the java.sql.Driver interface, as is the case with OracleDriver.

Once you register the Oracle JDBC drivers, you can create your connection using the DriverManager class. For more information on registering drivers and writing a connection string, see "First Steps in JDBC".

Class oracle.jdbc.driver.OracleConnection

This class extends standard JDBC connection functionality to create and return Oracle statement objects, set flags and options for Oracle performance extensions, and support type maps for Oracle objects.

"Performance Extensions" describes the performance extensions, including row prefetching, update batching, and metadata TABLE_REMARKS reporting.

Key methods include:

These oracle.jdbc.driver.OracleConnection methods are Oracle-defined extensions:

Class oracle.jdbc.driver.OracleStatement

This class extends standard JDBC statement functionality and is the superclass of the OraclePreparedStatement and OracleCallableStatement classes. Extended functionality includes support for setting flags and options for Oracle performance extensions on a statement-by-statement basis, as opposed to the OracleConnection class that sets these on a connection-wide basis.

"Performance Extensions" describes the performance extensions, including row prefetching and column type definitions.

Key methods include:

These oracle.jdbc.driver.OracleStatement methods are Oracle-defined extensions:

Class oracle.jdbc.driver.OraclePreparedStatement

This class extends standard JDBC prepared statement functionality, is a subclass of the OracleStatement class, and is the superclass of the OracleCallableStatement class. Extended functionality consists of set methods for binding oracle.sql.* types and objects into prepared statements, and methods to support Oracle performance extensions on a statement-by-statement basis.

"Performance Extensions" describes the performance extensions, including database update batching.

Key methods include:

Class oracle.jdbc.driver.OracleCallableStatement

This class extends standard JDBC callable statement functionality and is a subclass of the OracleStatement and OraclePreparedStatement classes. Extended functionality includes set methods for binding structured objects and oracle.sql.* objects into prepared statements, and get methods for retrieving data into oracle.sql.* objects.

Key methods include:

Class oracle.jdbc.driver.OracleResultSet

This class extends standard JDBC result set functionality, implementing get methods for retrieving data into oracle.sql.* objects.

Key methods include:

Class oracle.jdbc.driver.OracleResultSetMetaData

This class extends standard JDBC result set metadata functionality to retrieve information about Oracle result set objects.

Key methods include the following:

Oracle Stream Classes

Oracle uses many stream classes that extend standard Java stream classes to provide special functionality, such as writing directly to an Oracle database. The JDBC drivers use these classes which are in the oracle.jdbc.driver package but does not intend them for use by Java applications programmers. For more information on Java streams, see "Using Java Streams in JDBC".

Class oracle.jdbc.driver.OracleTypes

The OracleTypes class defines constants that JDBC uses to identify SQL types. Each variable in this class has a constant integer value. The oracle.jdbc.driver.OracleTypes class contains a copy of the standard Java java.sql.Types class and contains these additional Oracle type extensions:

As in java.sql.Types, all of the variable names are in all-caps.

JDBC uses the SQL types identified by the elements of the OracleTypes class in two main areas: registering output parameters and in the setNull() method of the PreparedStatement class.

OracleTypes and Registering Output Parameters

The SQL types in the OracleTypes class identify the SQL type of the output parameters in the registerOutParameter() method of the java.sql.CallableStatement and oracle.jdbc.driver.OracleCallableStatement classes.

These are the forms that registerOutputParameter() can take for CallableStatement and OracleCallableStatement:

CallableStatement.registerOutParameter(int index, int sqlType)

CallableStatement.registerOutParameter(int index, int sqlType, int scale)

OracleCallableStatement.registerOutParameter(int index, int sqlType, String 
sql_name)

In these prototypes, index represents the parameter index, sqlType represents the SQL datatype (one of the OracleTypes, in this case), sql_name represents the name given to the datatype (that is, the "named type"), and scale represents the number of digits to the right of the decimal point when sqlType is a NUMERIC or DECIMAL datatype.

Any output parameter datatype except STRUCT, ARRAY, or REF can use the two forms of CallableStatement.registerOutParameter().

The OracleCallableStatement form of registerOutParameter() can be used only when the output parameter is of type STRUCT, ARRAY, or REF and requires you to provide the name of the named type.

The following example uses a CallableStatement to call a procedure named procout, which returns a CHAR datatype. Note the use of the OracleTypes.CHAR SQL name in the registerOutParameter() method.

CallableStatement procout = conn.prepareCall ("BEGIN procout (?); END;");
      procout.registerOutParameter (1, OracleTypes.CHAR);
      procout.execute ();
      System.out.println ("Out argument is: " + procout.getString (1));

The next example uses a CallableStatement to call procout, which returns a STRUCT datatype. The form of registerOutParameter() requires you to specify the name of the SQL type, OracleTypes.STRUCT, as well as the SQL type name (that is, the name of the named type) EMPLOYEE.

The example assumes that no type mapping has been declared for the EMPLOYEE type, so it is retrieved into a STRUCT datatype. To retrieve the value of EMPLOYEE into the default STRUCT datatype, the statement object procout is cast to an OracleCallableStatement and the getSTRUCT() is applied.

CallableStatement procout = conn.prepareCall ("BEGIN procout (?); END;");
procout.registerOutParameter (1, OracleTypes.STRUCT, "EMPLOYEE");
procout.execute ();

// get the value into a STRUCT because it 
// is assumed that no type map has been defined
STRUCT emp = ((OracleCallableStatement)procout).getSTRUCT (1);
OracleTypes and the setNull() Method

The SQL types in the OracleTypes class identify the object, which the setNull() method sets to NULL. The setNull() method can be found in the java.sql.PreparedStatement and oracle.jdbc.driver.OraclePreparedStatement classes.

These are the forms that setNull() can take for PreparedStatement and OraclePreparedStatement classes:

PreparedStatement.setNull(int index, int sqlType)

OraclePreparedStatement.setNull(int index, int sqlType, String sql_name)

In these prototypes, index represents the parameter index, sqlType represents the SQL datatype (one of the OracleTypes, in this case), and sql_name represents the name given to the datatype (that is, the name of the "named type"). If you enter an invalid sqlType, a "Parameter Type Conflict" error is thrown.

You can use the PreparedStatement form of setNull() to set to NULL the value of an object of any datatype, except STRUCT, ARRAY, or REF.

You can use the OraclePreparedStatement form of setNull() only when you set to NULL the value of an object of datatype STRUCT, ARRAY, or REF.

The following example uses a PreparedStatement to insert a NULL numeric value into the database. Note the use of OracleTypes.NUMERIC to identify the numeric object that is set to NULL.

PreparedStatement pstmt =
    conn.prepareStatement ("INSERT INTO num_table VALUES (?)");

pstmt.setNull (1, OracleTypes.NUMERIC);
pstmt.execute ();

In this example, the prepared statement inserts a NULL STRUCT object of type EMPLOYEE into the database. Note that an OraclePreparedStatement is required to set a STRUCT object to NULL. Thus, the prepared statement pstmt must be cast to OraclePreparedStatement.

PreparedStatement pstmt =
conn.prepareStatement ("INSERT INTO employee_table VALUES (?)");

((OraclePreparedStatement)pstmt).setNull(1, OracleTypes.STRUCT, "EMPLOYEE");
pstmt.execute ();



Prev

Top

Next
Oracle
Copyright © 1999 Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index