Posted by lancea
on February 23, 2006 at 2:46 PM PST
JDBC 4.0 has introduced several new features which will be highlighted in blogs over the next few weeks. Today's focus is on the Wrapper Interface.
The Wrapper interface provides a mechanism for JDBC users to be able to access an instance of a resource which has been wrapped for architectural reasons. This mechanism helps to eliminate the need to use non-standard means to access vendor specific resources.
The following JDBC interfaces are subinterfaces of the Wrapper interface:
The Wrapper interface consists of two methods:
- isWrapperFor - Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.
- unwrap - Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.
Here is a simple example of using these new methods:
Statement stmt = conn.createStatement();
Class clzz = Class.forName("oracle.jdbc.OracleStatement");
os = stmt.unwrap(clzz);