DatabaseMetaData.getTablePrivileges() - Mailing list pgsql-jdbc
From | danap |
---|---|
Subject | DatabaseMetaData.getTablePrivileges() |
Date | |
Msg-id | 4CAE7105.1080805@ttc-cmc.net Whole thread Raw |
Responses |
Re: DatabaseMetaData.getTablePrivileges()
|
List | pgsql-jdbc |
Today I update the one of the development systems for the MyJSQLView project to test the PostgreSQL 9.0 database. Once the database was installed and also the latest JDBC 9.0-801 I tested the program. The application crashed and after some testing I attributed the exception to the empty string "" parameter for the schemaPattern argument in DatabaseMetaData.getTablePrivileges() for the JDBC. Well not sure the JDBC is really causing the problem, it is throwing the exception, but the error disappears when the same JDBC is used with the PostgreSQL 8.4.4 database. The Java API since I'm pretty sure 1.4 clearly indicates the empty string "" is valid for the schemaPattern parameter. " Parameters: schemaPattern - a schema name pattern; must match the schema name as it is stored in the database; "" retrieves those without a schema; null means that the schema name should not be used to narrow the search " Particulars, Exception, and Abbreviated Code attached. Source for the code, MyJSQLView_Access; http://code.google.com/p/myjsqlview/source/browse/ danap. -------------------------------------------------------- Linux Platform Java(TM) SE Runtime Environment (build 1.6.0_01-b06) postgresql-9.0-801.jdbc3.jar & postgresql-9.0.801.jdbc4.jar SQL version: PostgreSQL 8.4.4 (Works Fine) SQL version: PostgreSQL 9.0.1 (Crashes) Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(Unknown Source) at org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.addACLPrivileges(AbstractJdbc2DatabaseMetaData.java:2799) at org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.parseACL(AbstractJdbc2DatabaseMetaData.java:2878) at org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.getTablePrivileges(AbstractJdbc2DatabaseMetaData.java:2700) at com.dandymadeproductions.myjsqlview.MyJSQLView_Access.loadDBTables(MyJSQLView_Access.java:1559) at com.dandymadeproductions.myjsqlview.MyJSQLView_Access.accessCheck(MyJSQLView_Access.java:1200) at com.dandymadeproductions.myjsqlview.MyJSQLView_Access.actionPerformed(MyJSQLView_Access.java:628) ---------------------------------------------------------- DatabaseMetaData dbMetaData; ResultSet db_resultSet; try { dbMetaData = dbConnection.getMetaData(); db_resultSet = dbMetaData.getTables(catalog, schemaPattern, tableNamePattern, tableTypes); schemas.removeAllElements(); tables.removeAllElements(); while (db_resultSet.next()) { // ************************************************************ // PostgreSQL databases may have schemas that limit access to // tables by users. So make a check and remove tables that are // not accessable by the user. if (subProtocol.equals("postgresql")) { db_resultSet = dbMetaData.getTablePrivileges(db, "", "%"); while (db_resultSet.next()) { String tableName, grantee, user; tableName = db_resultSet.getString("TABLE_NAME"); if (tables.contains(tableName)) { grantee = db_resultSet.getString("GRANTEE"); user = MyJSQLView_Access.getCurrentUser(); if (tables.contains(tableName) && !grantee.equals(user)) tables.remove(tableName); } } } db_resultSet.close(); } catch (SQLException e) { throw e; }
pgsql-jdbc by date: