From: | Peter Mount <peter(at)retep(dot)org(dot)uk> |
---|---|
To: | Steve Wampler <swampler(at)noao(dot)edu> |
Cc: | postgres-interfaces <pgsql-interfaces(at)postgresql(dot)org> |
Subject: | Re: Detecting presence of database through JDBC? |
Date: | 2000-05-16 19:21:18 |
Message-ID: | Pine.LNX.4.10.10005162019590.6429-100000@maidast.retep.org.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
On Tue, 16 May 2000, Steve Wampler wrote:
>
> Is there a way to determine whether or not a particular database
> exists programmatically throught JDBC? I was expecting an
> exception to be thrown if the DriverManager.getConnection(url, user, pwd)
> method cannot complete, but instead I get a "FATAL" error that
> doesn't seem to be catchable.
The easiest way is to connect to the template1 database, then query the
system tables for the database. This is exactly how PSQL implements the -l
parameter.
PS: In standard JDBC, there is no way of geting a list of databases on a
particular server.
Peter
> (I'd like the program to automatically create a database if it doesn't
> yet exist and then populate it with the tables that are needed. Handling
> the tables is easy, but I haven't found a way around the test for the
> database yet...)
>
> Thanks for any help!
> Steve
> --
> Steve Wampler- SOLIS Project, National Solar Observatory
> swampler(at)noao(dot)edu
>
--
Peter T Mount peter(at)retep(dot)org(dot)uk
Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres
Java PDF Generator: http://www.retep.org.uk/pdf
From | Date | Subject | |
---|---|---|---|
Next Message | Raul Chirea | 2000-05-17 00:48:49 | Some errors are not reported thru ODBC driver. |
Previous Message | Steve Wampler | 2000-05-16 18:19:34 | Detecting presence of database through JDBC? |