What Are the Table's Privileges? JDBC

A database table’s privileges refers to finding a description of the access rights for each table available in a catalog or schema. DatabaseMetaData provides a method, getTablePrivileges(), to do just that. This method returns the result as a ResultSet where each row is a table privilege description. In web-based applications, returning the result as a ResultSet is not useful. It is better to return the result as an HTML/XML object so that the client can extract the required information and display it in a desired format. It would be wrong to assume that this privilege applies to all columns; while this may be true for some systems, it is not true for all.

getTablePrivileges() returns only privileges that match the schema and table name criteria. They are ordered by TABLE_SCHEM, TABLE_NAME, and PRIVILEGE. Each privilege description has the columns shown in Table.

Table : Result Columns for Invoking getTablePrivileges()

Result Columns for Invoking getTablePrivileges()

The getTablePrivileges() method has the following signature:

where

  • catalog is a catalog name; "" retrieves those without a catalog.
  • schemaPattern is a schema name pattern; "" retrieves those without a schema.
  • tableNamePattern is a table name pattern.

Next we’ll look at a Java servlet, GetTablePrivileges, which has the following signature:

The Solution

Invoking GetTablePrivileges for MySQL

Figure : shows how to run the solution for the MySQL database.

Invoking GetTablePrivileges for MySQLInvoking GetTablePrivileges for MySQL

Invoking GetTablePrivileges for Oracle

Figure : shows how to run the solution for the Oracle database.

Invoking GetTablePrivileges for OracleInvoking GetTablePrivileges for Oracle



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JDBC Topics