pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedCreating a database with JDBC
3+ messages / 3 participants
[nested] [flat]
* Creating a database with JDBC
@ 1998-09-27 17:22 Richard Heller <rheller@prime.cs.ohiou.edu>
0 siblings, 2 replies; 3+ messages in thread
From: Richard Heller @ 1998-09-27 17:22 UTC (permalink / raw)
To: pgsql-interfaces
Hi,
Is there any way to connect to the postgresql driver without having a
database already in existence? I want to have a Java program that can
check if a database already exists and create the database if it doesn't
exist.
The examples I've seen all seem to assume that a database has already been
created.
Thanks,
Rich
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [INTERFACES] Creating a database with JDBC
@ 1998-09-28 08:57 Herouth Maoz <herouth@oumail.openu.ac.il>
parent: Richard Heller <rheller@prime.cs.ohiou.edu>
1 sibling, 0 replies; 3+ messages in thread
From: Herouth Maoz @ 1998-09-28 08:57 UTC (permalink / raw)
To: Richard Heller <rheller@prime.cs.ohiou.edu>; pgsql-interfaces
At 19:22 +0200 on 27/9/98, Richard Heller wrote:
> Is there any way to connect to the postgresql driver without having a
> database already in existence? I want to have a Java program that can
> check if a database already exists and create the database if it doesn't
> exist.
>
> The examples I've seen all seem to assume that a database has already been
> created.
Not only for Java, but generally for Postgres: There is always a
"template1" database. That database gets created when you install Postgres.
If you want to issue database-manipulation commands in SQL, all you need to
do is to connect to "template1" as your database, and issue SQL commands
such as CREATE DATABASE.
If you want to detect whether a database exists, I think the information is
in one of the system catalogs, but I don't remember exactly which. Another
solution, of course, is to attempt to connect to it, and if the attempt
fails (should probably check what error message was returned), connect to
template1 and issue a CREATE DATABASE statement.
By the way, make sure your postgres server runs with the -i option, or you
won't be able to connect to it with Java.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [INTERFACES] Creating a database with JDBC
@ 1998-09-28 19:17 Cary B. O'Brien <cobrien@access.digex.net>
parent: Richard Heller <rheller@prime.cs.ohiou.edu>
1 sibling, 0 replies; 3+ messages in thread
From: Cary B. O'Brien @ 1998-09-28 19:17 UTC (permalink / raw)
To: rheller@prime.cs.ohiou.edu; +Cc: pgsql-interfaces
> Hi,
>
> Is there any way to connect to the postgresql driver without having a
> database already in existence? I want to have a Java program that can
> check if a database already exists and create the database if it doesn't
> exist
>
You should be able to connect to template1 and select * from pg_database
to see what databases exist.
-- cary
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~1998-09-28 19:17 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-09-27 17:22 Creating a database with JDBC Richard Heller <rheller@prime.cs.ohiou.edu>
1998-09-28 08:57 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1998-09-28 19:17 ` Cary B. O'Brien <cobrien@access.digex.net>
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