The Source for Java Technology Collaboration
User: Password:



Lance Andersen

Lance Andersen's Blog

JDBC 4.0 Wrapper Interface

Posted by lancea on February 23, 2006 at 02:46 PM | Comments (1)

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:

  • java.sql.Connection
  • java.sql.DatabaseMetaData
  • java.sql.ParameterMetaData
  • java.sql.ResultSet
  • java.sql.ResultSetMetaData
  • java.sql.Statement
  • javax.sql.Datasource

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");
  OracleStatement os;
  if(stmt.isWrapperFor(clzz)) {
     os = stmt.unwrap(clzz);
     os.defineColumnType(1, Types.NUMBER);
  }


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • I don't see how this would be useful. If you already decided to throw away the benefits of vendor independence in the first place, you don't need a standard way to do it.

    Posted by: erickson on February 26, 2006 at 12:26 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds