Received: from shaked.cc.openu.ac.il (shaked.cc.openu.ac.il [147.233.145.65]) by hub.org (8.8.8/8.8.8) with ESMTP id EAA13414 for ; Mon, 28 Sep 1998 04:56:59 -0400 (EDT) (envelope-from herouth@oumail.openu.ac.il) Received: from [147.233.159.109] (herouth@mac-herouth.pc.openu.ac.il [147.233.159.109]) by shaked.cc.openu.ac.il (8.8.5/8.8.5) with ESMTP id KAA29742; Mon, 28 Sep 1998 10:56:37 +0200 (IST) X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Mon, 28 Sep 1998 10:57:11 +0200 To: Richard Heller , pgsql-interfaces@postgreSQL.org From: Herouth Maoz Subject: Re: [INTERFACES] Creating a database with JDBC 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