getMetaData().getTables() behaviour with JDBC3 8.3 & 8.4 drivers on windows

Поиск
Список
Период
Сортировка
Искать

getMetaData().getTables() behaviour with JDBC3 8.3 & 8.4 drivers on windows

От:
"Panon, Paul-Andre" <Paul-AndrePanon@SierraSystems.com>
Дата:
The PostgreSQL driver appears to be causing some unexpected behaviour for the OpenNMS installer on Windows.

In the following code snippet, the table row set returned includes TABLEs, SEQUENCEs, and INDEXes. Shouldn't getTables be filtering out and returning only tables and views?

    public void databaseSetUser() throws SQLException {
        Connection adminConn = getAdminConnection();
        ResultSet rs = adminConn.getMetaData().getTables(null, "public", "%", null);
        HashSet objects = new HashSet();
        while (rs.next()) {
            m_out.println(rs.getString("TABLE_NAME")+" "+ rs.getString("TABLE_TYPE") +" "+ rs.getString("REMARKS"));
            objects.add(rs.getString("TABLE_NAME"));
        }
        PreparedStatement st = getAdminConnection().prepareStatement("ALTER TABLE ? OWNER TO ?");
        for (String objName : objects) {
            st.setString(1, objName);
            st.setString(2, m_user);
            m_out.println("Would perform ALTER TABLE " + objName + " OWNER TO " + m_user );
            /* st.execute(); */
        }
        st.close();
    }

----Notice Regarding Confidentiality----

This email, including any and all attachments, (this “Email”) is intended only for the party to whom it is addressed and may contain information that is confidential or privileged.  Sierra Systems Group Inc. and its affiliates accept no responsibility for any loss or damage suffered by any person resulting from any unauthorized use of or reliance upon this Email.  If you are not the intended recipient, you are hereby notified that any dissemination, copying or other use of this Email is prohibited.  Please notify us of the error in communication by return email and destroy all copies of this Email. Thank you.

Re: getMetaData().getTables() behaviour with JDBC3 8.3 & 8.4 drivers on windows

От:
dmp <danap@ttc-cmc.net>
Дата:
>
>
>The PostgreSQL driver appears to be causing some unexpected behaviour for the OpenNMS installer on Windows.
>
>In the following code snippet, the table row set returned includes TABLEs, SEQUENCEs, and INDEXes. Shouldn't getTables be filtering out and returning only tables and views?
>
>    public void databaseSetUser() throws SQLException {
>        Connection adminConn = getAdminConnection();
>        ResultSet rs = adminConn.getMetaData().getTables(null, "public", "%", null);
>

In your argument for getTables(catalog, schemaPattern, tableNamePattern, 
tableTypes) you
have specified a null for the tableTypes. That I believe does not place 
any restrictions on
the returned table, so VIEW and other types will be returned.

types - A list of table types, which must be from the list of table
           types returned from getTableTypes(), to include; null returns
            all types.

danap
FAQ