Devuelve un objeto que implementa la interfaz especificada para permitir el acceso a los métodos específicos del Controlador Microsoft JDBC para SQL Server.

Sintaxis

public <T> T unwrap(Class<T> iface)

Parámetros

iface

Una clase de tipo T que define una interfaz.

Valor devuelto

Un objeto que implementa la interfaz especificada.

Excepciones

Comentarios

El método unwrap queda definido por la interfaz java.sql.Wrapper, que se incorpora en las especificaciones de JDBC 4.0.

Es posible que las aplicaciones necesiten tener acceso a las extensiones para la API de JDBC que sean específicas del Controlador Microsoft JDBC para SQL Server. El método unwrap admite la acción de desencapsular para las clases públicas que extiende este objeto, si las clases tienen extensiones de proveedor.

La clase SQLServerCallableStatement implementa la clase ISQLServerPreparedStatement, la cual se extiende a partir de la clase ISQLServerStatement. Cuando se llama a este método, el objeto desencapsula las siguientes clases: SQLServerStatement, SQLServerPreparedStatement y SQLServerCallableStatement.

Para obtener más información, vea Contenedores e interfaces.

En el siguiente ejemplo de código se muestra cómo utilizar los métodos unwrap e isWrapperFor para comprobar las extensiones del controlador e invocar a los métodos específicos del proveedor, como setResponseBuffering y 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();
  }
} 

Vea también