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
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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");
}
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

Responses

Browse pgsql-jdbc by date

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