Query to Select BLOB Locator from the DBMS Declare the WebLogic Server java.sql Objects Begin SQL Exception Block Updating a CLOB Value Using a Prepared Statement

Using API Extensions in JDBC Drivers 5-17

5.2.6.1 Query to Select BLOB Locator from the DBMS

The BLOB Locator, or handle, is a reference to an Oracle Thin Driver BLOB: String selectBlob = select blobCol from myTable where blobKey = 666

5.2.6.2 Declare the WebLogic Server java.sql Objects

The following code presumes the Connection is already established: ResultSet rs = null; Statement myStatement = null; java.sql.Blob myRegularBlob = null; java.io.OutputStream os = null;

5.2.6.3 Begin SQL Exception Block

In this try catch block, you get the BLOB locator and access the Oracle BLOB extension. try { get our BLOB locator.. myStatement = myConnect.createStatement; rs = myStatement.executeQueryselectBlob; while rs.next { myRegularBlob = rs.getBlobblobCol; } Access the underlying Oracle extension functionality for writing. Cast to the OracleThinBlob interface to access the Oracle method. os = OracleThinBlobmyRegularBlob.getBinaryOutputStream; ... } catch SQLException sqe { System.out.printlnERRORgeneral SQE: + sqe.getMessage; } Once you cast to the Oracle.ThinBlob interface, you can access the Oracle supported methods.

5.2.6.4 Updating a CLOB Value Using a Prepared Statement

If you use a prepared statement to update a CLOB and the new value is shorter than the previous value, the CLOB will retain the characters that were not specifically replaced during the update. For example, if the current value of a CLOB is abcdefghij and you update the CLOB using a prepared statement with zxyw, the value in the CLOB is updated to zxywefghij. To correct values updated with a prepared statement, you should use the dbms_lob.trim procedure to remove the excess characters left after the update. See the Oracle documentation for more information about the dbms_lob.trim procedure. Note: When working with BLOBs and CLOBs referred to as LOBs, you must take transaction boundaries into account; for example, direct all readwrites to a particular LOB within a transaction. For additional information, refer to Oracle documentation about LOB Locators and Transaction Boundaries at the Oracle Web site at http:www.oracle.com . 5-18 Oracle Fusion Middleware Programming JDBC for Oracle WebLogic Server

5.3 Programming with Oracle Virtual Private Databases

An Oracle Virtual Private Database VPD is an aggregation of server-enforced, application-defined fine-grained access control, combined with a secure application context in the Oracle database server. To use VPDs in your WebLogic Server application, you would typically do the following: 1. Create a JDBC data source in your WebLogic Server configuration that uses the Oracle Thin driver. See Chapter 2, Using WebLogic JDBC in an Application, or Create JDBC data sources in the Oracle WebLogic Server Administration Console Help. 2. Do the following in your application: import weblogic.jdbc.extensions.WLConnection get a connection from a WLS JDBC data source Connection conn = ds.getConnection; Get the underlying vendor connection object oracle.jdbc.OracleConnection orConn = oracle.jdbc.OracleConnection WLConnectionconn.getVendorConnection; Set CLIENT_IDENTIFIER which will be accessible from USERENV naming context on the database server side orConn.setClientIdentifierclientId; perform application specific work, preferably using conn instead of orConn clean up connection before returning to WLS JDBC data source orConn.clearClientIdentifierclientId; As soon as you are finished with vendor-specific calls, nullify the reference to the physical connection. orConn = null; close the pooled connection conn.close;

5.3.1 Oracle VPD with WebLogic Server

WebLogic Server provides support for the oracle.jdbc.OracleConnection .setClientIdentitfier and oracle.jdbc.OracleConnection .clearClientIndentifier methods without using the underlying physical connection from a pooled connection. To use VPDs in your WebLogic Server application, you would typically do the following: import weblogic.jdbc.vendor.oracle.OracleConnection; get a connection from a WLS JDBC data source Connection conn = ds.getConnection; cast to the Oracle extension and set CLIENT_IDENTIFIER which will be accessible from USERENV naming context on the database server side Note: If you are using an XA-enabled version of the JDBC driver, you must set KeepXAConnTillTxComplete=true. See JDBC Data Source: Configuration: Connection Pool in the Oracle WebLogic Server Administration Console Help. Note: This code uses an underlying physical connection from a pooled logical connection.