12/54 3 JDBC Standards SupportThe Oracle Java Database Connectivity (JDBC) drivers support different versions of the JDBC standard features. In Oracle Database 11 g Release 2 (11.2), Oracle JDBC drivers have been enhanced to provide support for the JDBC 4.0 standards. These features are provided through the oracle.jdbc and oracle.sql packages. These packages support Java Development Kit (JDK) releases 1.5 and 1.6. This chapter discusses the JDBC standards support in Oracle JDBC drivers. It contains the following sections:.
Support for JDBC 2.0 StandardStandard JDBC 2.0 features are supported by JDK 1.2 and later versions. There are three areas to consider:.Support for data types, such as objects, arrays, and large objects (LOBs).
This is handled through the standard java.sql package.Support for standard features, such as result set enhancements and update batching. This is handled through standard objects, such as Connection, ResultSet, and PreparedStatement, under JDK 1.2.x and later.Support for extended features, such as features of the JDBC 2.0 optional package, also known as the standard extension application programming interface (API), including data sources, connection pooling, and distributed transactions.This section covers the following topics:. Standard versus Oracle Performance Enhancement APIsThe following performance enhancements are available under JDBC 2.0, which had previously been available only as Oracle extensions:.Update batching.Fetch size or row prefetchingIn each case, you have the option of using the standard model or the Oracle model. Oracle recommends that you use the JDBC standard model whenever possible. Do not, however, try to mix usage of the standard model and Oracle model within a single application for either of these features.
The full version string for this update release is 1.6.037-b06 (where 'b' means 'build') and the version number is 6u37. JDK 6u37 contains Olson time zone data version 2012c. For more information, refer to Timezone Data Versions in the JRE Software. The security baselines for the Java Runtime.
Retrieval of Auto-Generated KeysMany database systems automatically generate a unique key field when a row is inserted. Oracle Database provides the same functionality with the help of sequences and triggers. JDBC 3.0 introduces the retrieval of auto-generated keys feature that enables you to retrieve such generated values. In JDBC 3.0, the following interfaces are enhanced to support the retrieval of auto-generated keys feature:.java.sql.DatabaseMetaData.java.sql.Connection.java.sql.StatementThese interfaces provide methods that support retrieval of auto-generated keys. However, this feature is supported only when INSERT statements are processed. Other data manipulation language (DML) statements are processed, but without retrieving auto-generated keys.
Java.sql.StatementIf key columns are not explicitly indicated, then Oracle JDBC drivers cannot identify which columns need to be retrieved. When a column name or column index array is used, Oracle JDBC drivers can identify which columns contain auto-generated keys that you want to retrieve. However, when the Statement.RETURNGENERATEDKEYS integer flag is used, Oracle JDBC drivers cannot identify these columns. When the integer flag is used to indicate that auto-generated keys are to be returned, the ROWID pseudo column is returned as key. The ROWID can be then fetched from the ResultSet object and can be used to retrieve other columns.
Note:.You need to have the ojdbc6.jar in your classpath environment variable in order to have JDBC 4.0 standard support.The JDBC 4.0 specification defines the getClientInfo and setClientInfo methods to get and set client information. The 11.2 Oracle JDBC drivers do not define any client information, so any call to these methods throws a SQLClientInfoException exception.The JDBC 4.0 specification defines the java.sql.Connection.createArrayOf factory method to create java.sql.Array objects. The createArrayOf method accepts the name of the array element type as one of the arguments, where the array type is anonymous. Oracle database supports only named array types, not anonymous array types. So, the 11.2 Oracle JDBC drivers do not and cannot support the createArrayOf method. You must use the Oracle specific createARRAY method to create an array type.
For more information about the createArrayOf method, refer to.This document provides only an overview of these new features. For detailed information about these features, see 'Java 2 Platform, Standard Edition (JSE) 6.0 specification' atSome of the features available in Oracle Database 11 g Release 2 (11.2) JDBC drivers are the following:. Wrapper Pattern SupportWrapper pattern is a common coding pattern used in Java applications to provide extensions beyond the traditional JDBC API that are specific to a data source. You may need to use these extensions to access the resources that are wrapped as proxy class instances representing the actual resources. JDBC 4.0 introduces the Wrapper interface that describes a standard mechanism to access these wrapped resources represented by their proxy, to permit direct access to the resource delegates.The Wrapper interface provides the following two methods:.public boolean isWrapperFor(Class iface) throws SQLException;.public T unwrap(Class iface) throws SQLException;The other JDBC 4.0 interfaces, except those that represent SQL data, all implement this interface. These include Connection, Statement and its subtypes, ResultSet, and the metadata interfaces. Note:.You also need to include the xdb.jar and xmlparserv2.jar files in the classpath environment variable to use SQLXML type data, if they are not already present in the classpath.SQLXML is not supported in CachedRowset objects.You can create an instance of XML by calling the createSQLXML method in java.sql.Connection interface.
This method returns an empty XML object.The PreparedStatement, CallableStatement, and ResultSet interfaces have been extended with the appropriate getter and setter methods in the following way:.PreparedStatement: The method setSQLXML have been added.CallableStatement: The methods getSQLXML and setSQLXML have been added.ResultSet: The method getSQLXML have been addedThe oracle.jdbc.getObjectReturnsXMLType PropertyIn Oracle Database 10 g and earlier versions of Oracle Database 11 g, Oracle JDBC drivers supported the Oracle SQL XML type (XMLType) through an Oracle proprietary extension. XML values were represented by instances of the oracle.xdb.XMLType class and the SQL XMLType values were read and set through the JDBC standard getObject, setObject, and updateObject methods.The JDBC standard requires the getObject method to return an instance of java.sql.SQLXML type when called on a SQL XML type column. But, the earlier versions of Oracle JDBC drivers return an instance of oracle.xdb.XMLType. This does not conform to the JDBC standard.The current release of Oracle JDBC drivers conform to the JDBC standard with the introduction of a new connection property, oracle.jdbc.getObjectReturnsXMLType. If you set this property to false, then the getObject method returns an instance of java.sql.SQLXML type. You can achieve this by using the following command line option while compiling your program with javac:-Doracle.jdbc.getObjectReturnsXMLType='false'If you depend on the existing Oracle proprietary support for SQL XMLType using oracle.xdb.XMLType, then you can change the value of this property back to true by using the following command line option:-Doracle.jdbc.getObjectReturnsXMLType='true'The value of the oracle.jdbc.getObjectReturnsXMLType property is a String representing a boolean value of either true or false. If the value of this property is true, then the getObject method returns oracle.xdb.XMLType instances, when called for a SQL XMLType column.
This is the deafault value of the oracle.jdbc.getObjectReturnsXMLType property. If the value of this property is false, then the getObject method returns java.sql.SQLXML instances. This is the standard JDBC-compliant mode. Enhanced Exception Hierarchy and SQLExceptionJDBC 3.0 defines only a single exception, SQLException. However, there are large categories of errors and it is useful to distinguish them. This feature provides subclasses of the SQLException class to identify the different categories of errors.
The primary distinction is between permanent errors and transient errors. Permanent errors are a result of the correct operation of the system and will always occur. Transient errors are the result of failures, including timeouts, of some part of the system and may not reoccur.JDBC 4.0 adds additional exceptions to represent transient and permanent errors and the different categories of these errors.Also, the SQLException class and its subclasses are enhanced to provide support for the J2SE chained exception functionality.
The RowId Data TypeJDBC 4.0 provides the java.sql.RowId data type to represent SQL ROWID values. You can retrieve a RowId value using the getter methods defined in the ResultSet and CallableStatement interfaces. You can also use a RowId value in a parameterized PreparedStatement to set a parameter with a RowId object or in an updatable result set to update a column with a specific RowId value.A RowId object is valid until the identified row is not deleted. A RowId object may also be valid for the following:.The duration of the transaction in which it is created.The duration of the session in which it is created.An undefined duration where by it is valid foreverThe lifetime of the RowId object can be determined by calling the DatabaseMetaData.getRowIdLifetime method. LOB CreationIn JDBC 4.0, the Connection interface has been enhanced to provide support for the creation of BLOB, CLOB, and NCLOB objects. The interface provides the createBlob, createClob, and createNClob methods that enable you to create Blob, Clob, and NClob objects.The created large objects (LOBs) do not contain any data. You can add or retrieve data to or from these objects by calling the APIs available in the java.sql.Blob, java.sql.Clob, and java.sql.NClob interfaces.
You can either retrieve the entire content or a part of the content from these objects. The following code snippet illustrates how to retrieve 100 bytes of data from a BLOB object starting at offset 200.Connection con = DriverManager.getConnection(url, props);Blob aBlob = con.createBlob;// Add data to the BLOB object.aBlob.setBytes(.).// Retrieve part of the data from the BLOB object.InputStream is = aBlob.getBinaryStream(200, 100).You can also pass LOBs as input parameters to a PreparedStatement object by using the setBlob, setClob, and setNClob methods. You can use the updateBlob, updateClob, and updateNClob methods to update a column value in an updatable result set.These LOBs are temporary LOBs and can be used for any purpose for which temporary LOBs should be used. To make the storage permanent in the database, these LOBs must be written to a table.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |