Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

<Resource
    name="jdbc/phenome_repository"
    auth="Container"
    type="javax.sql.DataSource"
    username="correctUserName"
    password="correctPassword"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost/correctDatabaseName"    
/>

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 127.0.0.1 and the "correctUser" above has all the necessary privileges (on localhost and 127.0.0.1).

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

Full stacktrace

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

In my case it turns out another admin had denied ALL: ALL in hosts.deny and hosts.allow was empty. Placing mysqld: 127.0.0.1 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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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