简体   繁体   中英

Get All tables allowed to user with jdbc

I'm connecting to a database using jdbc, getting list of all schemas and tables from database (I assume that some databases may return at this point only tables which current user can query, but some of databases return full list of tables) and when user try to query some tables he get "insufficient privileges" error. Is there a way to get only tables, user can query using only jdbc capabilities? Without writing special query to database.

Now I'm looking at

      DatabaseMetaData dbMeta = connection.getMetaData() 
      dbMeta.getTablePrivileges(null, null, null);

But from result of this query it's not so clear which exactly tables can user query.

Currently I'm working with SAP HANA database, but in general it may be any database, so I'm looking for some common approach.

Please look at

http://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html#getTablePrivileges%28java.lang.String,%20java.lang.String,%20java.lang.String%29

You have to get the each row from the ResultSet and query of column name TABLE_NAME which contains the table name and PRIVILEGE which contains the access of each table.

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