I have a web application which accesses MySQL using Hibernate as a JPA provider. Though all is well on my development rig, once I deploy the WAR to my server I get the following error:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Cannot open connection

The dev machine runs Ubuntu 10.10 and the server 10.04; both are using the provided MySQL package and Apache's (not Ubuntu's) tomcat6. I have more than triple-checked that the database is running, the credentials are correct and the driver is available.
I have this Resource definition in tomcat's context.xml:


Since the web application works locally, I believe its configuration to be correct (it has a resource-ref in its web.xml). As for MySQL, it is configured to listen on and the "correctUser" above has all the necessary privileges (on localhost and

Does anyone know any less usual causes of "Cannot open connection"?

Full stacktrace


In my case it turns out another admin had denied ALL: ALL in hosts.deny and hosts.allow was empty. Placing mysqld: in hosts.allow fixed the problem.

For reference, here are all the potential causes of errors like the one I described:

  • localhost may not connect as per hosts.allow and hosts.deny
  • JDBC driver is not available to tomcat
  • The database is configured to disallow network connections
  • The database is not running

In each of these cases the full stacktrace will be subtly different. A missing driver will be more apparent in the stacktrace than the other causes listed here.

Please suggest any items missing from the above list.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.