返回一个实现指定接口的对象,从而允许访问特定于 Microsoft JDBC Driver for SQL Server 的方法。
语法
  
public <T> T unwrap(Class<T> iface)  
参数
iface
定义接口的类型为 T 的类。
返回值
实现指定接口的对象。
例外
备注
unwrap方法由在 JDBC 4.0 规范中引入的 java.sql.Wrapper 接口定义。
应用程序可能需要访问特定于 Microsoft JDBC Driver for SQL Server 的 JDBC API 扩展。 如果类公开供应商扩展,则 unwrap 方法支持对此对象扩展的公共类取消包装。
SQLServerCallableStatement 实现自 ISQLServerStatement 扩展而来的 ISQLServerPreparedStatement。 当此方法获调用时,对象会取消对下列类的包装:SQLServerStatement、SQLServerPreparedStatement 和 SQLServerCallableStatement。
有关详细信息,请参阅包装器和接口。
下面的代码示例展示了如何通过使用 isWrapperFor 和 unwrap 方法,检查驱动程序扩展并调用供应商专用方法(如 setResponseBuffering 和 getResponseBuffering)。
public static void executeStoredProcedure(Connection con) {  
   try {  
    CallableStatement cstmt =   
       con.prepareCall("{call dbo.stored_proc_name(?, ?)}");  
  
    // The recommended way to access the JDBC   
    // Driver-specific methods is to use the JDBC 4.0 Wrapper   
    // functionality.   
    // The following code statements demonstrates how to use the   
    // isWrapperFor and unwrap methods  
    // to access the driver-specific response buffering methods.  
  
    if (cstmt.isWrapperFor(  
      com.microsoft.sqlserver.jdbc.SQLServerCallableStatement.class)) {  
     // The CallableStatement object can unwrap to   
     // SQLServerCallableStatement.  
     SQLServerCallableStatement SQLcstmt =   
     cstmt.unwrap(  
        com.microsoft.sqlserver.jdbc.SQLServerCallableStatement.class);  
     SQLcstmt.setResponseBuffering("adaptive");  
     System.out.println("Response buffering mode has been set to " +  
         SQLcstmt.getResponseBuffering());  
     }  
  
    if (cstmt.isWrapperFor(  
      com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.class)) {  
      // The CallableStatement object can unwrap to   
      // SQLServerPreparedStatement.                    
      SQLServerPreparedStatement SQLpstmt =   
       cstmt.unwrap(  
       com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.class);  
      SQLpstmt.setResponseBuffering("adaptive");  
      System.out.println("Response buffering mode has been set to " +  
          SQLpstmt.getResponseBuffering());  
    }  
    if (cstmt.isWrapperFor(  
      com.microsoft.sqlserver.jdbc.SQLServerStatement.class)) {  
  
      // The CallableStatement object can unwrap to SQLServerStatement.   
      SQLServerStatement SQLstmt =   
        cstmt.unwrap(  
        com.microsoft.sqlserver.jdbc.SQLServerStatement.class);  
      SQLstmt.setResponseBuffering("adaptive");  
      System.out.println("Response buffering mode has been set to " +  
      SQLstmt.getResponseBuffering());  
    }  
  }  
  catch (Exception e) {  
     e.printStackTrace();  
  }  
}   
另请参阅
              isWrapperFor 方法 (SQLServerCallableStatement)
              SQLServerCallableStatement 成员
              SQLServerCallableStatement 类