有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java有没有办法检查RDBMS数据库表的读写信息?

我需要找到应用程序的RDBMS表元数据。我能够使用java.sql.DatabaseMetaData查找列元数据、表存在性,并通过对java.sql.Statement执行查询来查找行计数

需要怎么检查

  • 布尔canRead()
  • 布尔canWrite()

在桌子上

我在DatabaseMetaData类中找到了isReadOnly()方法。但它

Retrieves whether this database is in read-only mode.

有没有办法在表级别对RDBMS数据库进行常规检查


共 (1) 个答案

  1. # 1 楼答案

    你在找getTablePrivileges()

    Retrieves a description of the access rights for each table available in a catalog. Note that a table privilege applies to one or more columns in the table. It would be wrong to assume that this privilege applies to all columns (this may be true for some systems but is not true for all.)

    结果集中的PRIVILEGE列将包含您要查找的信息。如果我没记错的话,您将在结果中获得授予的每个特权的一行

    正如getTablePrivileges()的JavaDoc所建议的,您可能还需要检查getColumnPrivileges(),但这取决于您的用例和您希望支持的DBMS