Create a new database from JDBC?

Started by Dan Armbrustabout 20 years ago4 messagesgeneral
Jump to latest
#1Dan Armbrust
daniel.armbrust.list@gmail.com

How do I make a connection to a Postgresql database that (potentially)
has 0 databases from jdbc, so that I can issue a create database command?

In that _other_ database, I can make a jdbc connection to an address
like this:

jdbc:mysql://servername/

And then issue a "Create database foo" command.

Then I can reconnect to
jdbc:mysql://servername/foo

And everything is good.

If I try to connect to a postgresql database like this:

jdbc:postgresql://servername/

Postgres attempts to connect to a database that is named the same as the
username I provided.

Certainly not what I want, since that database doesn't exist. Is there
a system database I could always count on being available that I could
connect to?

Thanks,

Dan

--
****************************
Daniel Armbrust
Biomedical Informatics
Mayo Clinic Rochester
daniel.armbrust(at)mayo.edu
http://informatics.mayo.edu/

#2Joshua D. Drake
jd@commandprompt.com
In reply to: Dan Armbrust (#1)
Re: Create a new database from JDBC?

Dan Armbrust wrote:

How do I make a connection to a Postgresql database that (potentially)
has 0 databases from jdbc, so that I can issue a create database command?

In that _other_ database, I can make a jdbc connection to an address
like this:

jdbc:mysql://servername/

And then issue a "Create database foo" command.

Then I can reconnect to
jdbc:mysql://servername/foo

And everything is good.

If I try to connect to a postgresql database like this:

jdbc:postgresql://servername/

Postgres attempts to connect to a database that is named the same as
the username I provided.

Certainly not what I want, since that database doesn't exist. Is
there a system database I could always count on being available that I
could connect to?

template1 but only if you allow it from pg_hba.conf.

Show quoted text

Thanks,

Dan

#3Dave Page
dpage@pgadmin.org
In reply to: Joshua D. Drake (#2)
Re: Create a new database from JDBC?

On 8/2/06 17:26, "Joshua D. Drake" <jd@commandprompt.com> wrote:

Certainly not what I want, since that database doesn't exist. Is
there a system database I could always count on being available that I
could connect to?

template1 but only if you allow it from pg_hba.conf.

The postgres database would be more appropriate on 8.1+ (it is specifically
inteded for that kind of thing), however like template1, it can be dropped,
though that isn't advisable without good reason.

Regards, Dave.

#4Dan Armbrust
daniel.armbrust.list@gmail.com
In reply to: Dave Page (#3)
Re: Create a new database from JDBC?

Dave Page wrote:

On 8/2/06 17:26, "Joshua D. Drake" <jd@commandprompt.com> wrote:

Certainly not what I want, since that database doesn't exist. Is
there a system database I could always count on being available that I
could connect to?

template1 but only if you allow it from pg_hba.conf.

The postgres database would be more appropriate on 8.1+ (it is specifically
inteded for that kind of thing), however like template1, it can be dropped,
though that isn't advisable without good reason.

Regards, Dave.

So there is no guaranteed way to do this, unless there is a known,
existing database? Seems like a shortcoming, to me. Would this be
considered as a feature request, or does the current design make it to
difficult to implement?

Dan

--
****************************
Daniel Armbrust
Biomedical Informatics
Mayo Clinic Rochester
daniel.armbrust(at)mayo.edu
http://informatics.mayo.edu/