当前位置: 首页>>代码示例>>Java>>正文


Java DatabaseMetaData.getColumnPrivileges方法代码示例

本文整理汇总了Java中java.sql.DatabaseMetaData.getColumnPrivileges方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseMetaData.getColumnPrivileges方法的具体用法?Java DatabaseMetaData.getColumnPrivileges怎么用?Java DatabaseMetaData.getColumnPrivileges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.DatabaseMetaData的用法示例。


在下文中一共展示了DatabaseMetaData.getColumnPrivileges方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGetColumnPrivileges

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
@Test public void testGetColumnPrivileges() throws SQLException {
  DatabaseMetaData metadata = getDatabaseMetadata();
  try (ResultSet rs = metadata.getColumnPrivileges(null, null, null, null)) {
    ResultSetMetaData rsMeta = rs.getMetaData();

    assertEquals(8, rsMeta.getColumnCount());
    assertColumn(rsMeta, 1, "TABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
    assertColumn(rsMeta, 2, "TABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
    assertColumn(rsMeta, 3, "TABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
    assertColumn(rsMeta, 4, "COLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
    assertColumn(rsMeta, 5, "GRANTOR", Types.VARCHAR, DatabaseMetaData.columnNullable);
    assertColumn(rsMeta, 6, "GRANTEE", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
    assertColumn(rsMeta, 7, "PRIVILEGE", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
    assertColumn(rsMeta, 8, "IS_GRANTABLE", Types.VARCHAR, DatabaseMetaData.columnNullable);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:17,代码来源:MetaResultSetTest.java

示例2: testTwo

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
 * Basic test of DatabaseMetaData functions that access system tables
 */
public void testTwo() throws Exception {

    Connection conn = newConnection();
    int        updateCount;

    try {
        TestUtil.testScript(conn, "testrun/hsqldb/TestSelf.txt");

        DatabaseMetaData dbmeta = conn.getMetaData();

        dbmeta.allProceduresAreCallable();
        dbmeta.getBestRowIdentifier(null, null, "T_1",
                                    DatabaseMetaData.bestRowTransaction,
                                    true);
        dbmeta.getCatalogs();
        dbmeta.getColumnPrivileges(null, "PUBLIC", "T_1", "%");
        dbmeta.getColumns("PUBLIC", "PUBLIC", "T_1", "%");
        dbmeta.getCrossReference(null, null, "T_1", null, null, "T_1");
        dbmeta.getExportedKeys(null, null, "T_1");
        dbmeta.getFunctionColumns(null, "%", "%", "%");
        dbmeta.getFunctions(null, "%", "%");
        dbmeta.getImportedKeys("PUBLIC", "PUBLIC", "T_1");
        dbmeta.getIndexInfo("PUBLIC", "PUBLIC", "T1", true, true);
        dbmeta.getPrimaryKeys("PUBLIC", "PUBLIC", "T_1");
        dbmeta.getProcedureColumns(null, null, "%", "%");
        dbmeta.getProcedures("PUBLIC", "%", "%");
        dbmeta.getSchemas(null, "#");
        dbmeta.getTablePrivileges(null, "%", "%");
        dbmeta.getUDTs(null, "%", "%", new int[]{ Types.DISTINCT });
    } catch (Exception e) {
        assertTrue("unable to prepare or execute DDL", false);
    } finally {
        conn.close();
    }
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:39,代码来源:TestDatabaseMetaData.java

示例3: runOtherMetaDataTests

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
private void runOtherMetaDataTests() throws SQLException
{
	DatabaseMetaData metadata = connection.getMetaData();
	try (ResultSet rs = metadata.getCatalogs())
	{
	}
	try (ResultSet rs = metadata.getAttributes("", "", null, null))
	{
	}
	try (ResultSet rs = metadata.getClientInfoProperties())
	{
	}
	try (ResultSet rs = metadata.getFunctionColumns("", "", null, null))
	{
	}
	try (ResultSet rs = metadata.getFunctions("", "", null))
	{
	}
	try (ResultSet rs = metadata.getProcedureColumns("", "", null, null))
	{
	}
	try (ResultSet rs = metadata.getProcedures("", "", null))
	{
	}
	try (ResultSet rs = metadata.getSchemas())
	{
	}
	try (ResultSet rs = metadata.getSchemas("", null))
	{
	}
	try (ResultSet rs = metadata.getSuperTypes("", "", null))
	{
	}
	try (ResultSet rs = metadata.getTableTypes())
	{
	}
	try (ResultSet rs = metadata.getTypeInfo())
	{
	}
	try (ResultSet rs = metadata.getUDTs(null, null, null, null))
	{
	}
	for (String table : TABLES)
	{
		try (ResultSet rs = metadata.getExportedKeys("", "", table))
		{
		}
		try (ResultSet rs = metadata.getImportedKeys("", "", table))
		{
		}
		try (ResultSet rs = metadata.getBestRowIdentifier("", "", table, DatabaseMetaData.bestRowTransaction,
				false))
		{
		}
		try (ResultSet rs = metadata.getColumnPrivileges("", "", table, null))
		{
		}
		try (ResultSet rs = metadata.getPrimaryKeys("", "", table))
		{
		}
		try (ResultSet rs = metadata.getPseudoColumns("", "", table, null))
		{
		}
		try (ResultSet rs = metadata.getSuperTables("", "", table))
		{
		}
		try (ResultSet rs = metadata.getTablePrivileges("", "", table))
		{
		}
		try (ResultSet rs = metadata.getVersionColumns("", "", table))
		{
		}
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:75,代码来源:MetaDataTester.java

示例4: testGetColumnPrivilegesUsingInfoSchema

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
 * Tests the implementation of Information Schema for column privileges.
 */
public void testGetColumnPrivilegesUsingInfoSchema() throws Exception {
    String dontRunPropertyName = "com.mysql.jdbc.testsuite.cantGrant";

    if (!runTestIfSysPropDefined(dontRunPropertyName)) {
        if (versionMeetsMinimum(5, 0, 7)) {
            Properties props = new Properties();

            props.put("useInformationSchema", "true");
            Connection conn1 = null;
            Statement stmt1 = null;
            String userHostQuoted = null;

            boolean grantFailed = true;

            try {
                conn1 = getConnectionWithProps(props);
                stmt1 = conn1.createStatement();
                createTable("t1", "(c1 int)");
                this.rs = stmt1.executeQuery("SELECT USER()");
                this.rs.next();
                String user = this.rs.getString(1);
                List<String> userHost = StringUtils.split(user, "@", false);
                if (userHost.size() < 2) {
                    fail("This test requires a JDBC URL with a user, and won't work with the anonymous user. "
                            + "You can skip this test by setting the system property " + dontRunPropertyName);
                }
                userHostQuoted = "'" + userHost.get(0) + "'@'" + userHost.get(1) + "'";

                try {
                    stmt1.executeUpdate("GRANT update (c1) on t1 to " + userHostQuoted);

                    grantFailed = false;

                } catch (SQLException sqlEx) {
                    fail("This testcase needs to be run with a URL that allows the user to issue GRANTs "
                            + " in the current database. You can skip this test by setting the system property \"" + dontRunPropertyName + "\".");
                }

                if (!grantFailed) {
                    DatabaseMetaData metaData = conn1.getMetaData();
                    this.rs = metaData.getColumnPrivileges(null, null, "t1", null);
                    this.rs.next();
                    assertEquals("t1", this.rs.getString("TABLE_NAME"));
                    assertEquals("c1", this.rs.getString("COLUMN_NAME"));
                    assertEquals(userHostQuoted, this.rs.getString("GRANTEE"));
                    assertEquals("UPDATE", this.rs.getString("PRIVILEGE"));
                }
            } finally {
                if (stmt1 != null) {

                    if (!grantFailed) {
                        stmt1.executeUpdate("REVOKE UPDATE (c1) ON t1 FROM " + userHostQuoted);
                    }

                    stmt1.close();
                }

                if (conn1 != null) {
                    conn1.close();
                }
            }
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:68,代码来源:MetadataTest.java


注:本文中的java.sql.DatabaseMetaData.getColumnPrivileges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。