Skip site navigation (1) Skip section navigation (2)

getTables or code problem?

From: "Alessandro Depase" <alessandro(dot)depase(at)libero(dot)it>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: getTables or code problem?
Date: 2004-01-16 15:43:00
Message-ID: 000d01c3dc47$6d8ef520$0200a8c0@dedalus1 (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
Hi all,
I have a problem with the use of DatabaseMetaData.getTables.
This is the part of code I last tried:

DatabaseMetaData conMD = connection.getMetaData();
System.out.println("Driver Name:\t" + conMD.getDriverName());
System.out.println("Driver Version:\t" + conMD.getDriverVersion());
String[] tableType = {"TABLE"};
ResultSet tables = conMD.getTables("db2","public",null,tableType); //I tried
also "%" instead of null, with the same results and "", but founding nothing
for (int j = 1; j <= tables.getMetaData().getColumnCount(); j++) {
    System.out.print(tables.getMetaData().getColumnName(j) + "\t");
while ( {
    for (int j = 1; j <= tables.getMetaData().getColumnCount(); j++)
        System.out.print(tables.getObject(j) + "\t");

The result of the first 2 lines is interesting for you, I imagine:
Driver Name: PostgreSQL Native Driver
Driver Version: PostgreSQL 7.4 JDBC3 with SSL (build 209)

What is the problem? The list I see as output is the list of the catalog db1
(the one I connected to using the connection string:
jdbc:postgresql://myhost:5432/db1 - the schema is "public" in both cases).

Well, this can even sound good to me, but why can I see all the catalogs
using a
ResultSet catalogs = conMD.getCatalogs();

My problem is that in my application I want to have the full listing of
catalogs, choose one of them, so have the full listing of schemas (well, I
imagine that I can do this in a single step, because I cannot find any JDBC
method signature which expects a catalog as parameter to return schemas, so
it seems to me that schemas should be the same for all catalogues -?- ).
Choosing the schema I want to get the correct table listing.

Just another thing: the output of the code before seems to me a little odd:
the field 'table_cat' returns always null. Is this the reason? Is this

Maybe I misunderstood something, because there are others application (for
example, PgAdminIII) which give the correct list. But where is my error?

Thanks in advance

    Alessandro Depase


pgsql-jdbc by date

Next:From: Tom LaneDate: 2004-01-16 16:06:26
Subject: Re: Invalid SQL still executes valid sub transactions
Previous:From: Paul ThomasDate: 2004-01-16 15:26:39
Subject: Re: Invalid SQL still executes valid sub transactions in Prepared Statement

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group