Düzenle

Aracılığıyla paylaş


getColumnPrivileges Method (SQLServerDatabaseMetaData)

Download JDBC driver

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 SQL Server 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 AdventureWorks2022 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