pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
I can't get the database's list
3+ messages / 3 participants
[nested] [flat]

* I can't get the database's list
@ 2010-06-09 02:22  miguel manzano <miguel.miguelmanzano@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: miguel manzano @ 2010-06-09 02:22 UTC (permalink / raw)
  To: pgsql-jdbc

I try to obtain the database's list in my instalation but when I use :

 System.out.println("Driver : ");
         System.out.println("   " + md.getDatabaseProductName() );
         System.out.println("   " + md.getDatabaseProductVersion() );
         ResultSet catalogRs = md.getCatalogs();

         while ( catalogRs.next() ){
            
            System.out.println("Catalog " + catalogRs.getString(1));
            ResultSet tableRs =
md.getTables(catalogRs.getString(1),"%","%",(String []) null);
            }
        }
I just got only the name of the database at I have conected but the
another databases didn't figure in the list.
But if I use :
psql template1 -c "select datname from pg_catalog.pg_database"
I can see all databases in my machine.
I have read documentation but I haven't found where is the problem
please I need help about this topic
Thanks for all
Miguel Manzano
miguel.miguelmanzano@gmail.com-




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: I can't get the database's list
@ 2010-06-09 06:09  Kris Jurka <books@ejurka.com>
  parent: miguel manzano <miguel.miguelmanzano@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Kris Jurka @ 2010-06-09 06:09 UTC (permalink / raw)
  To: miguel manzano <miguel.miguelmanzano@gmail.com>; +Cc: pgsql-jdbc



On Tue, 8 Jun 2010, miguel manzano wrote:

> I try to obtain the database's list in my instalation but when I use :
>
> System.out.println("Driver : ");
>         System.out.println("   " + md.getDatabaseProductName() );
>         System.out.println("   " + md.getDatabaseProductVersion() );
>         ResultSet catalogRs = md.getCatalogs();
>
>         while ( catalogRs.next() ){
>
>            System.out.println("Catalog " + catalogRs.getString(1));
>            ResultSet tableRs =
> md.getTables(catalogRs.getString(1),"%","%",(String []) null);
>            }
>        }
> I just got only the name of the database at I have conected but the
> another databases didn't figure in the list.

The JDBC driver avoids returning all the databases on the server because 
it cannot access them.  It can only access the current database so that is 
all it returns from getCatalogs.  We made this decision intentionally to 
handle the exact situation that your next getTables call reveals.  If we 
returned other databases in getCatalogs, people would try to use them in 
other database metadata calls which would not work.

Kris Jurka




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: I can't get the database's list
@ 2010-06-09 06:14  Craig Ringer <craig@postnewspapers.com.au>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Craig Ringer @ 2010-06-09 06:14 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: miguel manzano <miguel.miguelmanzano@gmail.com>; pgsql-jdbc

On 09/06/10 14:09, Kris Jurka wrote:
> 
> 
> On Tue, 8 Jun 2010, miguel manzano wrote:
> 
>> I try to obtain the database's list in my instalation but when I use :
>>
>> System.out.println("Driver : ");
>>         System.out.println("   " + md.getDatabaseProductName() );
>>         System.out.println("   " + md.getDatabaseProductVersion() );
>>         ResultSet catalogRs = md.getCatalogs();
>>
>>         while ( catalogRs.next() ){
>>
>>            System.out.println("Catalog " + catalogRs.getString(1));
>>            ResultSet tableRs =
>> md.getTables(catalogRs.getString(1),"%","%",(String []) null);
>>            }
>>        }
>> I just got only the name of the database at I have conected but the
>> another databases didn't figure in the list.
> 
> The JDBC driver avoids returning all the databases on the server because
> it cannot access them.  It can only access the current database so that
> is all it returns from getCatalogs.  We made this decision intentionally
> to handle the exact situation that your next getTables call reveals.  If
> we returned other databases in getCatalogs, people would try to use them
> in other database metadata calls which would not work.

To elaborate: If you want to use queries "across databases" or otherwise
use more than one database in a single connection, you probably need to
use schema not databases to separate things.

PostgreSQL's "schema" are like MySQL's "databases"; they're ways of
dividing up naming of objects that live within the same storage space.

-- 
Craig Ringer

Tech-related writing: http://soapyfrogs.blogspot.com/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2010-06-09 06:14 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-06-09 02:22 I can't get the database's list miguel manzano <miguel.miguelmanzano@gmail.com>
2010-06-09 06:09 ` Kris Jurka <books@ejurka.com>
2010-06-09 06:14   ` Craig Ringer <craig@postnewspapers.com.au>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox