pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: Richard Heller <rheller@prime.cs.ohiou.edu>
To: pgsql-interfaces@postgreSQL.org
Subject: Re: [INTERFACES] Creating a database with JDBC
Date: Mon, 28 Sep 1998 10:57:11 +0200
Message-ID: <l03110702b234fe941e28@[147.233.159.109]> (raw)
In-Reply-To: <Pine.GSO.3.96.980927131912.9303F-100000@prime.cs.ohiou.edu>

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





view thread (3+ messages)  latest in thread

Message-ID: <l03110702b234fe941e28@[147.233.159.109]>
Permalink:  ../l03110702b234fe941e28@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03110702b234fe941e28@[147.233.159.109]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-interfaces@postgresql.org
  Cc: herouth@oumail.openu.ac.il, rheller@prime.cs.ohiou.edu
  Subject: Re: [INTERFACES] Creating a database with JDBC
  In-Reply-To: <l03110702b234fe941e28@[147.233.159.109]>
  References: <Pine.GSO.3.96.980927131912.9303F-100000@prime.cs.ohiou.edu> <l03110702b234fe941e28@[147.233.159.109]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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