getTables or code problem? - Mailing list pgsql-jdbc

From Alessandro Depase
Subject getTables or code problem?
Date
Msg-id 000d01c3dc47$6d8ef520$0200a8c0@dedalus1
Whole thread Raw
Responses Re: getTables or code problem?  (Kris Jurka <books@ejurka.com>)
List 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");
}
System.out.println();
while (tables.next()) {
    for (int j = 1; j <= tables.getMetaData().getColumnCount(); j++)
    {
        System.out.print(tables.getObject(j) + "\t");
    }
    System.out.println();
}

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
correct?

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

Bye
    Alessandro Depase




pgsql-jdbc by date:

Previous
From: Paul Thomas
Date:
Subject: Re: Invalid SQL still executes valid sub transactions in Prepared Statement
Next
From: Tom Lane
Date:
Subject: Re: Invalid SQL still executes valid sub transactions