Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 2F7949FBD40 for ; Wed, 21 Feb 2007 11:40:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 97209-01 for ; Wed, 21 Feb 2007 11:40:07 -0400 (AST) X-Greylist: delayed 00:06:38.399027 by SQLgrey-1.7.4 Received: from web39103.mail.mud.yahoo.com (web39103.mail.mud.yahoo.com [209.191.86.254]) by postgresql.org (Postfix) with SMTP id 3662F9FBD2B for ; Wed, 21 Feb 2007 11:40:06 -0400 (AST) Received: (qmail 24112 invoked by uid 60001); 21 Feb 2007 15:33:23 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=dI75RtTod1/L/OFYxXCmFRNPkxoFUAeevxjzltDAAmJPekaCIaWvPQzmdAqtaeLCEKDwy9Q313iYZGsIjZgpa7jctn7chmnCZd2XDVE4Hd9ss9hN1I1AGUFcHWvSK+hrFTEEOeLelxleNvBiIm5UAZejckezINBU9gyrhm5NRyU=; X-YMail-OSG: FCmXQHYVM1l1KFWbyWTKyU_Ri24eklxC.VTCrvfGnCl0uvyQLmGS.fy0MWLgHIDebvF3INFlCF6266WtuNIgTA8V2XETOFMHXEAd8BODKATZbYC0j6v9xSjVSDk_X9a6dsyodvnDjQvhbCY- Received: from [203.215.160.146] by web39103.mail.mud.yahoo.com via HTTP; Wed, 21 Feb 2007 07:33:23 PST Date: Wed, 21 Feb 2007 07:33:23 -0800 (PST) From: Altaf Malik Subject: Re: DatabaseMetaData.getCatalogs() To: Peter Futaro , pgsql-jdbc@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-681721953-1172072003=:23875" Content-Transfer-Encoding: 8bit Message-ID: <848835.23875.qm@web39103.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.607 tagged_above=0 required=5 tests=AWL, BAYES_40, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS, HTML_50_60, HTML_MESSAGE X-Spam-Level: * X-Archive-Number: 200702/113 X-Sequence-Number: 16669 --0-681721953-1172072003=:23875 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit JDBC does not allow to collect an information for the database you are not conected to. The method getCatalogs does not return databases, instead it returns the catalogs in current database. To list down the available databases, you need to query the catalog tables. For example, on postgres you can use : select datname from pg_catalog.pg_database where datname not in('template0','template1') This will populate all the databases. --Altaf Malik EnterpriseDB www.enterprisedb.com Peter Futaro wrote: Dear all, I have a remote machine, which is ushing Postgres v.7.4.11. This machine has 2 database : Database A & Database B I have a task to list out the available database inside that machine in a combo box. I have tried to using : public String getDBList() { String s = ""; try { Class.forName(sDriver); connection_this = DriverManager.getConnection(sURL, sUser, sPassword); dbMetaData_this = connection_this.getMetaData(); resultSet_this = dbMetaData_this.getCatalogs(); while(resultSet_this.next()) { if(!resultSet_this.isFirst()) s += ","; s += resultSet_this.getString(1); } return s; } catch(SQLException e) { return "error"; } } This will only return the database, that I state inside the URL (e.g. String sURL = "jdbc:postgresql://<>:5432/databaseA" ---> will return "databaseA" only). I try to connect without stating any database inside the URL, also cannot. Can you guys please help me ? Thank you. Peter Futaro --------------------------------- Don't get soaked. Take a quick peak at the forecast with theYahoo! Search weather shortcut. --0-681721953-1172072003=:23875 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit
JDBC does not allow to collect an information for the database you are not conected to. The method getCatalogs does not return databases, instead it returns the catalogs in current database. To list down the available databases, you need to query the catalog tables. For example, on postgres you can use :
 
select datname from pg_catalog.pg_database where datname not in('template0','template1')
 
This will populate all the databases.
 
--Altaf Malik
EnterpriseDB
www.enterprisedb.com

Peter Futaro <peterfutaro@gmail.com> wrote:
Dear all,

I have a remote machine, which is ushing Postgres v.7.4.11.
This machine has 2 database :
Database A & Database B

I have a task to list out the available database inside that machine in a combo box. I have tried to using :

public String getDBList()
    {
        String s = "";
       
        try
        {
            Class.forName(sDriver);
            connection_this = DriverManager.getConnection(sURL, sUser, sPassword);
            dbMetaData_this = connection_this.getMetaData();
            resultSet_this = dbMetaData_this.getCatalogs();

            while(resultSet_this.next())
            {
                if(!resultSet_this.isFirst())
                    s += ",";
               
                s += resultSet_this.getString(1);
            }
       
            return s;
        }
       
        catch(SQLException e)
        {
            return "error";
        }
    }

This will only return the database, that I state inside the URL
(e.g. String sURL = "jdbc:postgresql://<<ip>>:5432/databaseA"  ---> will return "databaseA" only).

I try to connect without stating any database inside the URL, also cannot.
Can you guys please help me ?

Thank you.

Peter Futaro


Don't get soaked. Take a quick peak at the forecast
with theYahoo! Search weather shortcut. --0-681721953-1172072003=:23875--