We need the PostgreSQL JDBC Driver,since Glassfish and its deployed applications are writen in Java. Drivers are available for download at http://jdbc.postgresql.org. For this experiment choose the JDBC4 driver.
Download the driver file postgresql-<version>.jdbc4.jar and copy it to the diretory [glassfish_home]/glassfish/domains/domain1/lib/.
Restart Glassfish in order to make it load the new database driver. I thought that adopting an OSGI architecture Glassfish would never need restarts again,but I was wrong. At least,the restarting process is faster than V2.
Enter in the administration console and go to Resources/JDBC/Connection Pools.
Create a new connection pool with the name [database_name]Pool,select the resource type javax.sql.ConnectionPoolDataSource,select the database vendor PostgreSQL and click next.
Select the datasource classname org.postgresql.ds.PGConnectionPoolDataSource and inform the following additional properties:
DatabaseName=[database-name]
Password=******* ;)
PortNumber=5432 (this is the default port but make sure that you are using the correct one)
ServerName=[server-name|ip]
User=<database-username>
Click Finish to save the new connection pool.
Go to the list of connection pools again and select the new one that you just created.
Click on Ping to check if the connection was correctly configured. The message "Ping Succeeded" means that the connection is working fine.
In order to be able to use this connection pool in JEE applications,we have to create a JNDI name for it. Go to Resources/JDBC/JDBC Resources.
Click on New and set the JNDI Name jdbc/[database_name],select the connection pool created above and click Ok to finish. This JNDI name will be used by applications to access the PostgreSQL database.