List of usage examples for java.sql DatabaseMetaData getTablePrivileges
ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException;
From source file:GetColumnPrivilegesOracle.java
public static void main(String[] args) throws Exception { Connection conn = null;/*w ww . ja va 2 s .c o m*/ 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(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); ResultSet privileges = null;//w w w.ja v a 2 s . c o m DatabaseMetaData meta = conn.getMetaData(); // The '_' character represents any single character. // The '%' character represents any sequence of zero // or more characters. privileges = meta.getTablePrivileges(conn.getCatalog(), "%", "survey"); 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); } st.close(); conn.close(); }
From source file:org.executequery.databaseobjects.impl.DefaultDatabaseHost.java
/** * Returns the priviliges of the specified object. * * @param catalog the table catalog name * @param schema the table schema name/*from www. j a v a 2s . c o m*/ * @param table the database object name */ public List<TablePrivilege> getPrivileges(String catalog, String schema, String table) throws DataSourceException { ResultSet rs = null; try { String _catalog = getCatalogNameForQueries(catalog); String _schema = getSchemaNameForQueries(schema); DatabaseMetaData dmd = getDatabaseMetaData(); List<TablePrivilege> privs = new ArrayList<TablePrivilege>(); rs = dmd.getTablePrivileges(_catalog, _schema, table); while (rs.next()) { privs.add(new TablePrivilege(rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7))); } return privs; } catch (SQLException e) { throw new DataSourceException(e); } finally { releaseResources(rs); } }