Connecting to a remote postgres database in GF 3.1.1
I have run into a problem trying to connect to a postgres (8.2) data base that is on a remote server. I am using Glassfish 3.1.1 and have also found the problem with Glassfish 2.1.1. I can setup the connection pool and ping the remote database, I can access the remote database from pgAdmin which is on the same server that GF 3.1.1 and 2.1.1 are running and I can access the remote database from Netbeans on the same server the GF is running. The code works with App Server 8.2 and Glassfish 2.1.1 but the database has alway been local to the Application Server. Both the database server and the Glassfish server are Solaris 10 x86. I looked at the server.policy file for both Glassfish 3.1.1 and 2.1.1 and they appear to allow connections. The application is using EJB 2.1 technology but that does not appear to be a problem as the connection problem occurs in a servlet or in an Enitity Bean that is accessed through a servlet and a Session Bean. Like I said this has worked for years with the database local to the App Server. What don't I know or have forgotten about connecting to a remote database from a Java Application Server?
Below is a paste of the server log indicating the error messager.
PWC1406: Servlet.service() for servlet LoginPwdServlet threw exception java.lang.reflect.UndeclaredThrowableException at $Proxy109.getClientInfo(Unknown Source) at com.sun.gjc.spi.jdbc40.ConnectionHolder40.getClientInfo(ConnectionHolder40.java:353) at com.sun.gjc.spi.jdbc40.ConnectionHolder40.init(ConnectionHolder40.java:81) at com.sun.gjc.spi.jdbc40.ConnectionHolder40.<init>(ConnectionHolder40.java:72) at com.sun.gjc.spi.jdbc40.Jdbc40ObjectsFactory.getConnection(Jdbc40ObjectsFactory.java:51) at com.sun.gjc.spi.ManagedConnection.getConnection(ManagedConnection.java:329) at com.sun.enterprise.resource.ConnectorAllocator.fillInResourceObjects(ConnectorAllocator.java:155) at com.sun.enterprise.resource.AbstractResourcePool.getResource(AbstractResourcePool.java:517) at com.sun.enterprise.resource.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:248) at com.sun.enterprise.resource.PoolManagerImpl.getResource(PoolManagerImpl.java:176) at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:337) at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:235) at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165) at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:158) at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:130) at LoginPwdServlet.doPost(LoginPwdServlet.java:159) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at
SOLUTION: The fix was to use the latest version of the postgresql jdbc driver. That is the postgresql-9.1-901.jdbc4.jar driver. One should also make sure that the version of the driver that is used in Glassfish to setup the connection pool is the same version that is in the application jar files. Although that was not my final problem I am sure I had that condition at one time.




