Re: [INTERFACES] Creating a database with JDBC

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Richard Heller <rheller(at)prime(dot)cs(dot)ohiou(dot)edu>, pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [INTERFACES] Creating a database with JDBC
Date: 1998-09-28 08:57:11
Message-ID: l03110702b234fe941e28@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message S.Ramaswamy 1998-09-28 14:12:34 Re: [INTERFACES] JDBC Connection refused
Previous Message Stan Thomas 1998-09-28 07:08:29 subscribe