Get the Column Privileges

From Java Example Source Code

Jump to: navigation, search

Contents

[edit] Overview - Get the Column Privileges

This Java example program shows how to get the column privileges.

[edit] Java Source Code

  • Package: example.jdbc.oraclejdbc
  • File: GetColumnPrivilegesOracle.java
package example.jdbc.oraclejdbc;
 
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);
    }
 
}

[edit] What Result You Can Get

Coming soon...

[edit] Required External Libraries and/or Files for this Java Example

In order to run this Java example, one of the following libraries may be required: In order to run this example program, one of the following libraries may be required:


[edit] How to Run this Java Example Program

We recommend running this Java example program with Eclipse.

For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.

It's fairly easy.



[edit] Question & Answer

Any question?

Click edit and post your question or answer here.


Personal tools