Get Column Privileges Oracle : Privileges « Database SQL JDBC « Java






Get Column Privileges Oracle

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class GetColumnPrivilegesOracle {
  public static void main(String[] args) throws Exception {
    Connection conn = null;

    conn = getConnection();
    String catalogPattern = conn.getCatalog();
    String schemaPattern = "SYSTEM";
    String tableNamePattern = "HELP";

    ResultSet privileges = null;
    DatabaseMetaData meta = conn.getMetaData();

    // The '_' character represents any single character.
    // The '%' character represents any sequence of zero or more characters.
    privileges = meta.getTablePrivileges(catalogPattern, schemaPattern, tableNamePattern);
    while (privileges.next()) {

      String catalog = privileges.getString("TABLE_CAT");
      String schema = privileges.getString("TABLE_SCHEM");
      String tableName = privileges.getString("TABLE_NAME");
      String privilege = privileges.getString("PRIVILEGE");
      String grantor = privileges.getString("GRANTOR");
      String grantee = privileges.getString("GRANTEE");
      String isGrantable = privileges.getString("IS_GRANTABLE");
      
      System.out.println("table name:" + tableName);
      System.out.println("catalog:" + catalog);
      System.out.println("schema:" + schema);
      System.out.println("privilege:" + privilege);
      System.out.println("grantor:" + grantor);
      System.out.println("isGrantable:" + isGrantable);
      System.out.println("grantee:" + grantee);
      conn.close();

    }
  }

  public static Connection getConnection() throws Exception {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:databaseName";
    String username = "system";
    String password = "password";
    Class.forName(driver); // load Oracle driver
    return DriverManager.getConnection(url, username, password);
  }

}
           
       








Related examples in the same category

1.Get Table Privileges