I've got a J2EE application (Tomcat) which uses Postgresql as the database. This app works fine in development but is failing when I try it on my staging environment.

I suspect I've got some kind of database communication problem but I'm not getting any errors that indicate exactly what it might be. Does anybody have an easy way to show that my app is successfully connecting to the database and running queries?

My evidence for a database problem is from examining the code. I'm getting a null pointer exception and the most likely path to get a null back is if the code somehow didn't manage to insert the object into the database.

For interest's sake, my staging environment is Ubuntu running on EC2 and this app is using Spring JDBC for most database access. Oh, and yes I do have the postgresql JDBC jar in the tomcat lib directory (although there seems some disagreement in documentation as to whether it should be in lib or common/lib). I've also been a bad boy and have been making changes to the expanded WAR file to try different things out.

I've turned the Tomcat Security Manager off and I'm connecting as the postgres superuser (yes, I know both of these things are bad long term but it'd be nice if it started running before I added restrictions).

Many thanks for any help.


Look in your postgres logs, you should see FATAL messages if you're having failed connections. If you don't it might be that you're not even reaching the database, so you'd need to verify nothing is in the way (firewall, selinux, etc) and/or that the database is configured to match your code's expectations.

One other tip would be to try and connect to the new server using a different client (I recommend psql) with the same credentials your code is using. If you can connect with psql, you have a problem with your code, if not, the problem is likely between the db or with the db configuration itself.


Just turn on query logging (set log_min_duration_statement to 0) to show you (a) what queries are being executed, and (b) how long each one is taking (not so interesting now, perhaps, but give it time...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy