3

I'm using Spring Boot with the following application.properties file for my database setup:

spring.datasource.url=jdbc:mysql://<my heroku cleardb host...>/<my db>
spring.datasource.username=<some user...>
spring.datasource.password=<some pass...>
spring.datasource.driverClassName=com.mysql.jdbc.Driver

I'm hosting my site on Heroku with ClearDB MySQL Database. My app keeps getting disconnected from the MySQL DB and it's because of this (from their support team):

To jump in here about this issue - the reason is that our systems automatically close all idle connections after 90 seconds of inactivity. This could be the reason you are running into this issue, especially if your connection pool is not properly configured to "ping" connections in less than around 90 seconds. Our recommendation would be to set the connection pool configuration to ping all pooled connections once every 60 seconds for safe keeping.

So the question is...how can I "ping" my connections every 60 seconds? I would like to believe that there is a way to set a spring.datasource property to do this but I'm having trouble finding a 'ping' property.

Zack Macomber
  • 6,682
  • 14
  • 57
  • 104
  • 1
    possible duplicate of [Ping a MySQL server](http://stackoverflow.com/questions/4569956/ping-a-mysql-server) – Branislav Lazic Oct 23 '14 at 15:46
  • I could ping MySQL programmatically but I would like to know if there's a `spring.datasource` property I can set for "pinging" the server – Zack Macomber Oct 23 '14 at 15:50
  • If you are using i.e. `Apache DBCP`, you could use `testOnBorrow` to validate your connections. Also, you would have to set `validationQuery` to `SELECT 1`. – Branislav Lazic Oct 23 '14 at 15:53
  • Check the Spring Boot docs [for properties](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#common-application-properties). Look at the test properties and validation query. At least you want the test on borrow that way if the connection is borked it will reconnect – M. Deinum Oct 23 '14 at 19:41

0 Answers0