title: OpenShift app can't connect to MySQL : JDBCConnectionException: Could not open connection
body: <p>I generated a .war file for my SpringMVC + Maven + Hibernate + MySQL app which was working perfectly fine on localhost and local MySQL database. The way I configure the database is through a WebAppConfig.java file which looks at an application.properties file and retrieves the appropriate information.</p>
  
  <p>Then I created an OpenShift account and deployed that .war file. I added MySQL and PHPMyAdmin cartridges so I can maintain a database. When I try to retrieve information or push to the database through my application I receive this error.</p>
  
  <blockquote>
    <p>HTTP Status 500 - Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection</p>
    
    <p><strong>message</strong> Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection</p>
    
    <p><strong>exception</strong> org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
        org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
        org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:722)</p>
  </blockquote>
  
  <p>I already added the appropriate information for my database in my properties file so I don't think that is the issue.</p>
  
  <p><strong>application.properties</strong></p>
  
  <pre><code>#DB
  db.driver = com.mysql.jdbc.Driver
  db.url = jdbc:mysql://{OPENSHIFT_MYSQL_DB_HOST}:{OPENSHIFT_MYSQL_DB_PORT}/springmvc
  db.username = {OPENSHIFT_MYSQL_DB_USERNAME}
  db.password = {OPENSHIFT_MYSQL_DB_PASSWORD}
  
  #Hibernate
  hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
  hibernate.show_sql = true
  entitymanager.packages.to.scan = org.example.app.model
  hibernate.cache.provider_class = org.hibernate.cache.NoCacheProvider
  </code></pre>
  
  <p>Note: In my actual code I have the actual OPENSHIFT_MYSQL_DB_HOST and OPENSHIFT_MYSQL_DB_PORT values not those placeholders!</p>