简体   繁体   中英

how to check database table permissions in java? (DataBase independently)

Does anyone know a way (in java) to check permissions to a specific table for a user? It has to work on the most Databases. SELECT right is simple to check (just trying to execute a simple SELECT statement), but how to check INSERT permission?

You can use the DatabaseMetaData to get this information. It should work in most cases. However, it might be inaccurate in special cases, if the privileges can not be represented in this abstract way:

DatabaseMetaData metaData connection.getMetaData();
metaData.getTablePrivileges();
metaData.getColumnPrivileges();

尽管这不是直接的解决方案,但是我想到的唯一选择是使用TRY CATCH块,发出INSERT语句,然后检查异常情况下返回的java.sql.SQLException对象中的错误消息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM