views:

310

answers:

2

Hi all
I have an application on Glassfish v2 ( on Mac OS 10.5.8 and Java 1.6 ) that uses JavaDB and Toplinks that comes with the Glassfish bundle. Everything works fine.

I have installed PostgreSQL 8.4 and the JDBC v4 driver. Both Glassfish and Postgres server run on localhost. From Netbeans, I create a connection to a database on the Postgres server, and it works fine, I can manually create and delete tables.

I create a connection pool, resource and persistence unit for this connection to the Posgres server. When I deploy I have the following error :

ADM1041:Sent the event to instance:
    [ResourceDeployEvent -- reference-added jdbc/jdbc/MyDatasource]
CORE5004: Resource Deployed: [jdbc:jdbc/MyDatasource].
TopLink, version: Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))
Server: unknown
RAR5038:Unexpected exception while creating resource for pool MyConnectionPool.  
Exception : Connection could not be allocated because: 
    FATAL: database "null" does not exist

I read that with Postgres 8.4, localhost request are accepted by default, so I haven't changed anything in postgres.conf.

I am missing something, but I cant see what. Thanks in advance for any hint.

Tart

A: 

I don't know the stack, but it sounds like you haven't specified the database name in the connection. See http://jdbc.postgresql.org/documentation/84/connect.html for a list of parameters you can/should set on the connection.

Magnus Hagander
I think the connection is ok, as I can manually access the database using it. It is define this way : <property name="URL" value="jdbc:postgresql://localhost:5432/MyDB"/> <property name="User" value="postgres"/> <property name="Password" value="foo"/>
Tart
+1  A: 

First ensure that MacOSX/GlassFish really uses the specified Java version (test with: java -version). Then try the following:

asadmin create-jdbc-connection-pool 
   --datasourceclassname org.postgresql.ds.PGSimpleDataSource 
   --restype javax.sql.DataSource --property portNumber=5432:password=secret:user=postgres:serverName=localhost:databaseName=postgres 
   test-pool

and

asadmin create-jdbc-resource --connectionpoolid test-pool jdbc/Postgres

remember to change the username, password, server, port and database to reflect your setup. Then test the datasource using:

asadmin ping-connection-pool test-pool

if this does not work then you have miss-configured your data source.

Lars Tackmann
The first phrase makes no sense. JDBC4 requires Java SE 6, not Java EE 6. Java EE 5 can run perfectly on top of Java SE 6. This is not the problem.
BalusC
Thanks. The driver was actually correct, but creating the ConnectionPool directly in the JavaEE server instead of doing via Netbeans worked. I am not sure what I did wrong setting the ConnectionPool via the wizard in Netbeans though, but at least the problem is solved :o)
Tart
fixed the the JDBC driver version part, as correctly pointed out by BalusC.
Lars Tackmann