Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't know if it is the best way to handle database connection, but I had the same problems as you described. I tried a lot and ended up with the <a href="http://sourceforge.net/projects/c3p0/" rel="nofollow noreferrer">c3p0 connection pool</a>.</p> <p>Using c3p0 you could force your app to refresh the database connection after a certain time.</p> <p>Place the <code>c3p0.jar</code> into your <code>lib</code> folder and add your configuration to <code>conf/spring/resources.groovy</code>.</p> <p>My <code>resources.groovy</code> looks like this:</p> <pre><code>import com.mchange.v2.c3p0.ComboPooledDataSource import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH beans = { /** * c3P0 pooled data source that forces renewal of DB connections of certain age * to prevent stale/closed DB connections and evicts excess idle connections * Still using the JDBC configuration settings from DataSource.groovy * to have easy environment specific setup available */ dataSource(ComboPooledDataSource) { bean -&gt; bean.destroyMethod = 'close' //use grails' datasource configuration for connection user, password, driver and JDBC url user = CH.config.dataSource.username password = CH.config.dataSource.password driverClass = CH.config.dataSource.driverClassName jdbcUrl = CH.config.dataSource.url //force connections to renew after 4 hours maxConnectionAge = 4 * 60 * 60 //get rid too many of idle connections after 30 minutes maxIdleTimeExcessConnections = 30 * 60 } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload