Thread: 'FATAL: database "null" does not exist ' when accessing through a datasource

'FATAL: database "null" does not exist ' when accessing through a datasource

From
"Joeseph Blowseph"
Date:
I've set up a datasource to access a database on the local machine. The
database was installed in the default location on the default port. Whenever
I try to make a connection to the database I get an error, usually this one.

org.postgresql.util.PSQLException: FATAL: database "null" does not exist

I've tried every conceivable permuation of the url (and a few inconceivable
ones). The datasource is set up like this:


DataSourceClass:    org.postgresql.ds.PGSimpleDataSource
JNDI Name:                jdbc/PGSimple
URL:                          jdbc:postgresql://localhost:5432/PGSQL1

And the code to access it is like this:

        InitialContext ic = new InitialContext();
    PGSimpleDataSource  PGDS =
        (PGSimpleDataSource) ic.lookup("jdbc/PGSimple);
        Connection PGSimpleConn = PGDS.getConnection();
        /* do Stuff /*
    PGSimpleConn.close();

That code fails with the above error. But if I add this statement, it works
okay:

PGDS.setDatabaseName("PGSQL1");

I can't understand why I can't specify the databasename in the URL.

The container is OC4J running in Oracle Jdeveloper.

Any thoughts would be very much appreciated.

_________________________________________________________________
Are you using the latest version of MSN Messenger? Download MSN Messenger
7.5 today! http://messenger.msn.co.uk


Re: 'FATAL: database "null" does not exist ' when accessing

From
Oliver Jowett
Date:
Joeseph Blowseph wrote:

> DataSourceClass:    org.postgresql.ds.PGSimpleDataSource
> JNDI Name:                jdbc/PGSimple
> URL:                          jdbc:postgresql://localhost:5432/PGSQL1

If you're using a DataSource, then the internal JDBC URL to use is
constructed from the parameters used to configure the datasource
(setDatabaseName, etc).

I don't know what your container is doing with the "JDBC URL" bit, but
AFAIK it's not used by the datasource at all.

-O

Re: 'FATAL: database "null" does not exist ' when accessing through a

From
"Joeseph Blowseph"
Date:
The datasource construction parameters are stored in a data-sources xml file
like this:

  <native-data-source name="PGDS1"
    data-source-class="org.postgresql.ds.PGPoolingDataSource"
    jndi-name="jdbc/PGPooling"
    user="postgres" password="password"
    url="jdbc:postgresql://localhost:5432/PGSQL1"/>

...

The program code does a jdni lookup for the DataSource. That means that you
don't have to hard-code connection details into the source. But, as things
stand, I have to hard-code the database name.




>From: Oliver Jowett <oliver@opencloud.com>
>To: Joeseph Blowseph <joseph_blowseph@hotmail.com>
>CC: pgsql-jdbc@postgresql.org
>Subject: Re: [JDBC] 'FATAL: database "null" does not exist ' when accessing
>through a datasource
>Date: Sat, 14 Jan 2006 11:21:12 +0000
>
>Joeseph Blowseph wrote:
>
>>DataSourceClass:    org.postgresql.ds.PGSimpleDataSource
>>JNDI Name:                jdbc/PGSimple
>>URL:                          jdbc:postgresql://localhost:5432/PGSQL1
>
>If you're using a DataSource, then the internal JDBC URL to use is
>constructed from the parameters used to configure the datasource
>(setDatabaseName, etc).
>
>I don't know what your container is doing with the "JDBC URL" bit, but
>AFAIK it's not used by the datasource at all.
>
>-O

_________________________________________________________________
The new MSN Search Toolbar now includes Desktop search!
http://toolbar.msn.co.uk/


Re: 'FATAL: database "null" does not exist ' when accessing

From
Oliver Jowett
Date:
Joeseph Blowseph wrote:
> The datasource construction parameters are stored in a data-sources xml
> file like this:
>
>  <native-data-source name="PGDS1"
>    data-source-class="org.postgresql.ds.PGPoolingDataSource"
>    jndi-name="jdbc/PGPooling"
>    user="postgres" password="password"
>    url="jdbc:postgresql://localhost:5432/PGSQL1"/>
>
> ...
>
> The program code does a jdni lookup for the DataSource. That means that
> you don't have to hard-code connection details into the source. But, as
> things stand, I have to hard-code the database name.

Sorry, I guess I wasn't clear.

Your container will be constructing a PGPoolingDataSource object, then
calling various JavaBean-property-style methods on it to initialize it.
These are methods such as setUser(), setPassword(), and setDatabaseName().

When PGPoolingDataSource is asked for a connection, it constructs a
driver URL from the various properties it is configured with and then
requests a connection with that URL.

The set of properties provided by a particular DataSource implementation
can vary -- the container is meant to use introspection to find and
invoke the property accessors.

PGPoolingDataSource does not have a "url" property, it does not provide
setURL() or similar. So I don't know what the container is doing with
that "url" parameter, but it's not being set on the DataSource for sure.
As the URL you specify never makes it to the DataSource, it's not
suprising that the information you specify there is not used.

You need to persuade your container to call the JavaBean accessor
setDatabaseName() on the DataSource before use. Perhaps you could try
adding an attribute called databaseName to your <native-data-source>
configuration element above?

This is why manually calling setDatabaseName fixes the "problem" -- but
it's the container's job to call it, as you say. So complain to your
container's vendor.. the PG datasource is working as designed, AFAIK.

-O

Re: 'FATAL: database "null" does not exist ' when accessing through a

From
"Joeseph Blowseph"
Date:
Thanks for the comprehensive answer.

I was assuming that the container was parsing the database name from the
URL. I've also been running into an "Invalid Oracle URL" error while I've
been trying to get this working. That didn't seem to make much sense when
the driver specified is Postgres. I think the two errors may be related.

Oracle profess their container to be database-independent, but I'm not so
sure! I have a thread open in the Oracle forum and I did feel that the
problem lies with them; I just thought I'd ask here to see if I could get
any further clarification. And I did  :-)


>From: Oliver Jowett <oliver@opencloud.com>
>To: Joeseph Blowseph <joseph_blowseph@hotmail.com>
>CC: pgsql-jdbc@postgresql.org
>Subject: Re: [JDBC] 'FATAL: database "null" does not exist ' when accessing
>through a datasource
>Date: Sun, 15 Jan 2006 10:24:01 +1300
>
>Joeseph Blowseph wrote:
>>The datasource construction parameters are stored in a data-sources xml
>>file like this:
>>
>>  <native-data-source name="PGDS1"
>>    data-source-class="org.postgresql.ds.PGPoolingDataSource"
>>    jndi-name="jdbc/PGPooling"
>>    user="postgres" password="password"
>>    url="jdbc:postgresql://localhost:5432/PGSQL1"/>
>>
>>...
>>
>>The program code does a jdni lookup for the DataSource. That means that
>>you don't have to hard-code connection details into the source. But, as
>>things stand, I have to hard-code the database name.
>
>Sorry, I guess I wasn't clear.
>
>Your container will be constructing a PGPoolingDataSource object, then
>calling various JavaBean-property-style methods on it to initialize it.
>These are methods such as setUser(), setPassword(), and setDatabaseName().
>
>When PGPoolingDataSource is asked for a connection, it constructs a driver
>URL from the various properties it is configured with and then requests a
>connection with that URL.
>
>The set of properties provided by a particular DataSource implementation
>can vary -- the container is meant to use introspection to find and invoke
>the property accessors.
>
>PGPoolingDataSource does not have a "url" property, it does not provide
>setURL() or similar. So I don't know what the container is doing with that
>"url" parameter, but it's not being set on the DataSource for sure. As the
>URL you specify never makes it to the DataSource, it's not suprising that
>the information you specify there is not used.
>
>You need to persuade your container to call the JavaBean accessor
>setDatabaseName() on the DataSource before use. Perhaps you could try
>adding an attribute called databaseName to your <native-data-source>
>configuration element above?
>
>This is why manually calling setDatabaseName fixes the "problem" -- but
>it's the container's job to call it, as you say. So complain to your
>container's vendor.. the PG datasource is working as designed, AFAIK.
>
>-O

_________________________________________________________________
Are you using the latest version of MSN Messenger? Download MSN Messenger
7.5 today! http://messenger.msn.co.uk