Nota
O acesso a esta página requer autorização. Podes tentar iniciar sessão ou mudar de diretório.
O acesso a esta página requer autorização. Podes tentar mudar de diretório.
Retorna um objeto que implementa a interface especificada para permitir o acesso ao Microsoft JDBC Driver para métodos específicos do SQL Server.
Sintaxe
public <T> T unwrap(Class<T> iface)
Parâmetros
iface
Uma classe do tipo T que define uma interface.
Valor de retorno
Um objeto que implementa a interface especificada.
Exceções
Observações
O método unwrap é definido pela interface java.sql.Wrapper, que é introduzida na especificação do JDBC 4.0.
Os aplicativos podem precisar acessar extensões para a API JDBC que são específicas para o Microsoft JDBC Driver para SQL Server. O método unwrap oferece suporte a desempacotamento para classes públicas que esse objeto estende, se as classes expõem extensões de fornecedor.
SQLServerCallableStatement implementa ISQLServerPreparedStatement, que é estendido a partir do ISQLServerStatement. Quando esse método é chamado, o objeto é desempacotado para as seguintes classes: SQLServerStatement, SQLServerPreparedStatement e SQLServerCallableStatement.
Para obter mais informações, consulte Wrappers e interfaces.
O exemplo de código a seguir demonstra como usar o isWrapperFor e unwrap métodos para verificar as extensões de driver e invocar os métodos específicos do fornecedor, como setResponseBuffering e 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();
}
}
Ver também
Método isWrapperFor (SQLServerCallableStatement)
Membros SQLServerCallableStatement
SQLServerCallableStatement Classe