Share via


unwrap メソッド (SQLServerCallableStatement)

JDBC ドライバーのダウンロード

指定されたインターフェイスを実装するオブジェクトを返します。このメソッドから返されたオブジェクトを使用することで、SQL Server 用 Microsoft JDBC ドライバー 固有のメソッドにアクセスできます。

構文

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

パラメーター

iface

インターフェイスを定義する T 型のクラスです。

戻り値

指定されたインターフェイスを実装するオブジェクトです。

例外

SQLServerException

解説

unwrap メソッドは、JDBC 4.0 仕様で導入された java.sql.Wrapper インターフェイスで定義されています。

アプリケーションは SQL Server 用 Microsoft JDBC ドライバー に固有の JDBC API 拡張機能にアクセスする必要がある場合があります。 unwrap メソッドは、クラスがベンダー拡張を公開する場合、このオブジェクトが拡張するパブリック クラスへのアンラッピングをサポートします。

SQLServerCallableStatement は、ISQLServerStatement クラスから拡張された ISQLServerPreparedStatement クラスを実装します。 このメソッドが呼び出されると、オブジェクトは SQLServerStatementSQLServerPreparedStatement、および SQLServerCallableStatement の各クラスにアンラップされます。

詳細については、「ラッパーとインターフェイス」を参照してください。

次のコード例では、isWrapperFor メソッドと unwrap メソッドを使用してドライバー拡張を確認し、setResponseBufferinggetResponseBuffering などのベンダー固有メソッドを呼び出す方法を示します。

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 クラス