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

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 SQL Server 2005 AdventureWorks 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