Startups : Rajesh Ramchandani's Weblog

Monday Jun 27, 2005

PostgreSQL with Sun Java System Application Server 8.1

Recently we tested out Open source databases (Postgresql and MySQL) for their JDBC Compliance and their capabilities to work with J2EE compliant Application servers such as Sun Java System Application server 8.1. Dave Cramer, the lead JDBC developer for PostgreSQL and Lance Obermeyer of Pervasive Software Inc. offered their engineering support and implemented the missing functions, data conversion routines and also fixed several bugs to be able to pass the JDBC compliance and also other tests (CMP/EJB tests) that any backend must pass in order to be Compliant to work with J2EE certified Application servers. All the changes and fixes that were done in the driver aren't part of the community release yet, but will be soon in near future. Also, we needed support for Stored procedures, so we had to use Postgresql 8.1-dev development release.

In order to make PostgreSQL work with Sun Java System Application server 8.1, you need to create a .tpersistence.properties file under $J2EE_HOME/domains//config directory and add the following:
database.postgresql.QUOTE_CHAR_END=
database.postgresql.QUOTE_CHAR_START=
database.postgresql.RTRIM=
database.postgresql.RTRIM_POST=
database.postgresql.SQRT=SQRT
database.postgresql.ABS=ABS

Creating Connection Pool

To create Connection Pools for Postgresql, under Admin server console:

1. Under Resources, select JDBC and on right hand side frame, select Connection Pools

2. Click on New to add create a new connection pool

3. Provide some name such as postgresql-pool and select Datasource type as javax.sql.ConnectionPoolDataSource

4. Click Next and enter the Datasource Classname as org.postgresql.ds.PGSimpleDataSource

5. Add the following properties to the connection pool:

DatabaseName <your-db-name>

port <your-selected-port-number> default port is 5432

user <DB-User-Name>

Password <DB-User-Password>

ServerName <DB-Server-Name>

Save the settings and click on Ping. If DB server is running and connection can be made, Ping will succeed. Please make sure you have copied the Postgresql jdbc driver in $J2EE_HOME/domains/<domain-name>/lib/ext directory.

Here's an sample domain.xml from an working installation:

<jdbc-connection-pool connection-validation-method="auto-commit" datasource-lassname="org.postgresql.ds.PGSimpleDataSource" fail-all-connections="false"  idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="false"  max-pool-size="96" max-wait-time-in-millis="60000"  name="cts-postgresql-pool" pool-resize-quantity="2" res-type="javax.sql.DataSource  "  steady-pool-size="32">
        <property name="DatabaseName" value="ctsinout"/>       
        <property name="port" value="5432"/>
        <property name="user" value="postgres"/>
        <property name="ServerName" value="magnolia"/>
        <property name="password" value="postgres"/>
        <property name="prepareThreshold" value="3"/>                Use Server Side Stored procedures        
        <property name="loglevel" value="2"/>                                DEBUG Level log
        <property name="protocolVersion" value="2"/>    
        <property name="ssl" value="true"/>  
</jdbc-connection-pool>

Restart the domains using "asadmin stop-domain and asadmin start-domain " or use Web based Admin server for the application server. Please note that this list of entries in the .tpersistence.properties file was sufficient for our work with the testsuite, however there may be more entries required depending on the sql usage.

You can read Lance Andersen's blogs for using Derby with Sun java System Application server at:
Derby with Sun Java Application Server

and Jonathan Bruce's blog for using MySQL with Sun Java System Application Server at:
MySQL with Sun Java Application Server

If you use Postgresql or are planning to use in near future and have questions about PostgreSQl on Solaris platform or questions, issues with Sun Java System application server with PostgreSQL (or MySQL), please feel free to contact me.

Comments:

Well,, i went by your described way of setting up a posgresql connection pool and sun app. server 8.1,, but failed..... The error on pinging is:- Operation 'pingConnectionPool' failed in 'resources' Config Mbean. Target exception message: Class name is wrong or classpath is not set for : org.posgtresqlds.PGSimpleDataSource your help was appreciated... but i will be looking for further help to attain success in my task. Thanks in advance... Abhinav

Posted by Abhinav Rawal on September 30, 2005 at 04:27 AM PDT #

Can you confirm your class name is org.posgtresql.ds.PGSimpleDataSource and not org.posgtresqlds.PGSimpleDataSource? Make sure you have the hdbc driver in the App servers' class path (or in ext directory as explained above).

Posted by Rajesh Ramchandani on September 30, 2005 at 10:32 AM PDT #

Hi there, I am having a similar problem, the error message is: Class name is wrong or classpath is not set for : org.posgtresql.ds.PGSimpleDataSource Can you please advise me where to put the postgresql-8.0-312.jdbc3.jar or postgresql-8.1dev-401.jdbc3.jar files? I have tried extracting the contents of one of them to /opt/SUNWappserver/domains/domain1/lib/ext , but I still get the same error message. I have also tried changing the suffix path in the JVM setting for the Sun server to point to each of the following locations: /opt/SUNWappserver/domains/domain1/lib/postgresql-8.1dev-401.jdbc3.jar /opt/SUNWappserver/domains/domain1/lib/ /opt/SUNWappserver/domains/domain1/lib/ext /opt/SUNWappserver/domains/domain1/lib/ext/org/postgresql/ds/ /opt/SUNWappserver/domains/domain1/lib/ Neither of those locations worked. Whenever I made a config change I restarted the server. I'm at a loss to explain why the server can't find the file really. I followed the explanation given by http://docs.sun.com/source/819-0076/jdbc.html to integrate the postgresql jdbc driver but it just doesn't seem to work. Also, what do you mean by this: $J2EE_HOME/domains//config ? Do you mean $J2EE_HOME/domains/domain1/config?? Hope to hear from you soon, I'm quite confused by this error.

Posted by Ahmed Kamal on October 04, 2005 at 01:41 AM PDT #

Amhed, the jdbc driver should be in <J2EE_HOME>/domains/domain1/lib/ext and you have it there. Can you pls send me the domain.xml and the relevant snippet of server.log?

Posted by Rajesh Ramchandani on October 04, 2005 at 10:13 AM PDT #

I found the source of the problem for both myself and Abhinav Rawal:

4. Click Next and enter the Datasource Classname as org.posgtresql.ds.PGSimpleDataSource

I had copied and pasted this from this page without checking and finding the typo. Its a simple mistake Rajesh and I thank you for being such a big help by looking thru my files to find the problem but now that I have identified it I hope you can fix the typo asap.

Thank you once again!

Posted by Ahmed Kamal on October 05, 2005 at 03:30 AM PDT #

Ahmed, The class name that I used and specified in the blog is not a typo. I am using non-pooling datasource and that's what you have to choose when you select datasource type (javax.sql.DataSource or java.xsql.ConnectionPooldataSource). In your case you were specifying class name as PGSimpleDataSource but choosing the type as javax.sql.ConnectionPoolDataSource, which will not work. I hope this clarifies. Abhnav, can you pls tell us if your problem is resolved as well?

Posted by Rajesh Ramchandani on October 05, 2005 at 09:08 AM PDT #

Hi Rajesh,
I don't intend to sound rude, but:
org.posgtresql.ds.PGSimpleDataSource
is a typo. There is no 'posgtresql' library. Its 'postgresql'. Even in your recent reply you specified:
java.xsql.ConnectionPooldataSource
when in fact the correct spelling is:
javax.sql.ConnectionPoolDataSource
Previously I was having a problem of the server not even being able to find the class file, it has nothing to do with what type of datasource I set in the Sun server settings. Everything has been resolved now that I have changed the spelling, and like I said previously- please fix this typo so that others don't make the same mistake I did.
Also what do you mean by this: $J2EE_HOME/domains//config ? Do you mean $J2EE_HOME/domains/domain1/config??

Posted by Ahmed Kamal on October 05, 2005 at 07:03 PM PDT #

Ahmed, Thanks for pointing the typo. I just overlooked it when you last pointed it out. Apologize for that. I had issues making ConnectionPooiling work with Postgresql ConnectionPoolDataSource. Do you have it working?

Posted by Rajesh Ramchandani on October 09, 2005 at 12:47 PM PDT #

Jones: Please make sure that: a) copy the .jar file into <domain>\lib\ext and b) restart Sun JAS. ... Ping will do the job after that ;o)

Posted by 212.151.198.78 on November 15, 2005 at 10:11 AM PST #

I tried to use the information found here with a postgresql instance running on port 5433. But it looks like the setting "port" is ignored by the application server. I tested it by referring a database which resides on port 5432 but not on 5433, and the ping succeeds. So I'd say that the port setting is ignored. My server is version 8.2 running on Debian Linux.

Posted by Akos Gabriel on June 09, 2006 at 01:14 PM PDT #

Hi there, i have no problem pinging the database from the admin console after creating the connection pool. I created then the JDBC resource using that pool with a jndi name jdbc/mobileac. But doing a context.lookup("java:comp/env/jdbc/mobileac"); raises javax.naming.NameNotFoundException: No object bound to name java:comp/env/jdbc/mobileac (the same lookup code works on a Tomcat server) What would be the problem ? Thanks in advance ...

Posted by arnaud on September 13, 2006 at 09:31 AM PDT #

Solution found to my problem : a context.lookup("jdbc/mobileac") works to get the data source. Why the lookup is different on Tomcat is another question ...

Posted by arnaud on September 14, 2006 at 09:36 AM PDT #

Hi, I was having exactly the same problem pinging connection pools. I searched the internet and lead me to this blog. I read the discussions and I solved the problem. Thanks a lot. Keep it up. You help people.

Posted by henry on December 15, 2006 at 11:33 PM PST #

hi all after doing all the above steps, i am still getting exception: javax.servlet.ServletException: Exception Description: Attempted to deploy PersistenceUnit [WebApplication6PU] for which predeploy method either had not called or had failed root cause Exception [TOPLINK-28013] (Oracle TopLink Essentials - 2006.8 (Build 060830)): oracle.toplink.essentials.exceptions.EntityManagerSetupException Exception Description: Attempted to deploy PersistenceUnit [WebApplication6PU] for which predeploy method either had not called or had failed

Posted by raj on February 24, 2007 at 03:26 AM PST #

Raj - I am not sure why you see oracle exceptions. You can work with some engineer at Sun to debug the problem. If you are a startup company, you may be able to use Startups Ask Sun at http://www.sun.com/startupessentials. Send in your questions and someone will help you. BTW, since I wrote this blog, I have moved to marketing at Sun and haven't had any hands-on work ever since.

Posted by Rajesh on February 25, 2007 at 09:35 PM PST #

hi there,
sorry if i sound too plan in my letter. is just that i can seem to find the datasource classname for sql server. please help me out .

Posted by Innocent on November 16, 2007 at 08:19 AM PST #

i fouund problem in pinging that the classpath is not set or classname is not found.I have checked the above given solutions but still i am facing this problem.If I want to send you my .xml file and the error screenshots on which link i can send?

Posted by ramsha on October 20, 2008 at 03:24 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Calendar

Feeds

Search

Links

Navigation

Referrers