LKBEN11150: Howto configure a connection pool for a postgres database in glassfish


Symptom

You need to create a connection pool and this need a jdbc driver to be configured

Cause

none

Solution

Before you can use any postgres sql databases via jdbc with a glassfish server you need to download the jdbc driver from http://jdbc.postgresql.org. Now you need to copy the driver (e.g. postgresql-8.3-604.jdbc4.jar) to your domain\lib directory. (e.g. on a windows system you need to copy to C:\Programme\glassfish-v2.1\domains\domain1\lib on a linux system you need to copy to /opt/glassfish/domains/domain1/lib or maybe some other path on your system)

Now you can create a connection pool which can be used to create a jdbc resource. This can be done in the glassfish admin console on e.g. http://localhost:4848.

1. launch the admin console. Default on: http://localhost:4848
2. Login in as Admin
3. Go to Resources/JDBC/Connection Pools
4. Click on new to start the JDBC Connection Pool Wizard
5. Name: e.g. mypostgrespool
6. Resource Type javax.sql.DataSource
7. Database Vendor: PostgreSQL
8. Click on Next
9. You must configure your settings e.g. user, password, ...
10. Click on OK to create the JDBC Resource
11. I recommend to make a ping on the data source (button on the top of the page)

Before using the jdbc resource you should try a ping from the connection pool to make shure your connection functions. I always set the database name, portnumber (default: 5432), a user and a password as a minimum. You can test if the setting are right with the psql command. e.g.

psql -U username databasename

This has to work first, otherwise your pool cannot function! If the ping on the data source does not work, you do not have to test with your java classes, it will not work. This has to be configured first before programming any data access. If you can read "Ping succeeded" everything has been configured correctly. Now you can start programming and using your database.

Disclaimer:

The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!

About the Author

Author: Wim Peeters - Keskon GmbH & Co. KG

Wim Peeters is electronics engineer with an additional master in IT and over 30 years of experience, including time spent in support, development, consulting, training and database administration. Wim has worked with SQL Server since version 6.5. He has developed in C/C++, Java and C# on Windows and Linux. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform.