Skip to content

Latest commit

 

History

History
107 lines (82 loc) · 3.71 KB

File metadata and controls

107 lines (82 loc) · 3.71 KB
title getColumnPrivileges Method (SQLServerDatabaseMetaData) | Microsoft Docs
ms.custom
ms.date 01/19/2017
ms.prod sql
ms.prod_service connectivity
ms.reviewer
ms.technology connectivity
ms.topic conceptual
apiname
SQLServerDatabaseMetaData.getColumnPrivileges
apilocation
sqljdbc.jar
apitype Assembly
ms.assetid 4ab6a671-9573-4b95-8c23-364306c60d25
author David-Engel
ms.author v-daenge

getColumnPrivileges Method (SQLServerDatabaseMetaData)

[!INCLUDEDriver_JDBC_Download]

Retrieves a description of the access rights for the columns in a table.

Syntax

  
public java.sql.ResultSet getColumnPrivileges(java.lang.String catalog,  
                                              java.lang.String schema,  
                                              java.lang.String table,  
                                              java.lang.String col)  

Parameters

catalog

A String that contains the catalog name.

schema

A String that contains the schema name.

table

A String that contains the table name.

col

A String that contains the column name pattern.

Return Value

A SQLServerResultSet object.

Exceptions

SQLServerException

Remarks

This getColumnPrivileges method is specified by the getColumnPrivileges method in the java.sql.DatabaseMetaData interface.

The result set returned by the getColumnPrivileges method will contain the following information:

Name Type Description
TABLE_CAT String The catalog name.
TABLE_SCHEM String The table schema name.
TABLE_NAME String The table name.
COLUMN_NAME String The column name.
GRANTOR String The object granting the access.
GRANTEE String The object receiving the access.
PRIVILEGE String The type of access granted.
IS_GRANTABLE String Indicates if the grantee is allowed to grant access to other users.

Note

For more information about the data returned by the getColumnPrivileges method, see "sp_column_privileges (Transact-SQL)" in [!INCLUDEssNoVersion] Books Online.

Example

The following example demonstrates how to use the getColumnPrivileges method to return the access rights for the FirstName column in the Person.Contact table in the [!INCLUDEssSampleDBnormal] sample database.

public static void executeGetColumnPrivileges(Connection con) {  
   try {  
      DatabaseMetaData dbmd = con.getMetaData();  
      ResultSet rs = dbmd.getColumnPrivileges("AdventureWorks", "Person", "Contact", "FirstName");  
      ResultSetMetaData rsmd = rs.getMetaData();  
  
      // Display the result set data.  
      int cols = rsmd.getColumnCount();  
      while(rs.next()) {  
         for (int i = 1; i <= cols; i++) {  
            System.out.println(rs.getString(i));  
         }  
      }  
      rs.close();  
}  
  
   catch (Exception e) {  
      e.printStackTrace();  
   }  
}  

See Also

SQLServerDatabaseMetaData Methods
SQLServerDatabaseMetaData Members
SQLServerDatabaseMetaData Class