<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DBWS.NET &#187; DBCP</title>
	<atom:link href="http://www.dbws.net/blog/tag/dbcp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dbws.net/blog</link>
	<description>Software development mutterings and maybe a little something about myself.</description>
	<lastBuildDate>Wed, 09 Nov 2011 16:56:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Grails 2 DataAccessResourceFailureException Solved</title>
		<link>http://www.dbws.net/blog/2010/02/15/grails-2-dataaccessresourcefailureexception-solved/</link>
		<comments>http://www.dbws.net/blog/2010/02/15/grails-2-dataaccessresourcefailureexception-solved/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 14:15:20 +0000</pubDate>
		<dc:creator>Bolo</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[DBCP]]></category>
		<category><![CDATA[GRAILS]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.dbws.net/blog/?p=29</guid>
		<description><![CDATA[For those using MYSQL and have either updated to grails version 2 or starting with grails 2 and have run into this exception then this solution works perfectly well for me. The problem is releated to Grails running out of connections to MySQL over time, &#38; not freeing stale connections.Â  I believe it happens when [...]]]></description>
			<content:encoded><![CDATA[<p>For those using MYSQL and have either updated to grails version 2 or starting with grails 2 and have run into this exception then this solution works perfectly well for me.</p>
<p>The problem is releated to Grails running out of connections to MySQL over time, &amp; not freeing stale connections.Â  I believe it happens when there hasn&#8217;t been activity for over 8 hours, which in my case happened everyday due to the overnight period.</p>
<p>So what we should be doing is managing our own database connection pool.Â Â  I use Tomcat 6 on my production servers so the following solution is specifically for tomcat 6.</p>
<p>What we need to do is first change our application configuration so it sets up a database connection pool through tomcat.Â  And secondly we need to tweak the configuration so that we validate the connection is present periodically and removed stale connections.</p>
<p>The first thing then is to define the connection pool in &lt;your application dir&gt;/web-app/META-INF/context.xml</p>
<p>A typical context.xml would be :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;Context path=&quot;/MyApplication&quot;&gt;
&lt;Resource
 auth=&quot;Container&quot;
 driverClassName=&quot;com.mysql.jdbc.Driver&quot;
 maxActive=&quot;20&quot;
 maxIdle=&quot;10&quot;
 maxWait=&quot;-1&quot;
 removeAbandoned=&quot;true&quot;
 name=&quot;jdbc/myAppsPool&quot;
 type=&quot;javax.sql.DataSource&quot;
 url=&quot;jdbc:mysql://localhost:3306/Database_Name&quot;
 username=&quot;user&quot;
 password=&quot;password&quot;
 validationQuery=&quot;SELECT '1'&quot;
 removeAbandonedTimeout=&quot;60&quot;
 logAbandoned=&quot;true&quot;/&gt;
&lt;/Context&gt;</pre>
<p>This alone will create the necessary database connection pool when you application is deployed.</p>
<p>All thats left to do now is to change your datasource configuration to refer to the connection pool so in your DataSource.groovy file, locate the production section and alter it to refer to the new pool, e.g :</p>
<pre class="brush: groovy; title: ; notranslate">production {
  dataSource {
    pooled = false
    dbCreate = &quot;update&quot;
    jndiName = &quot;java:comp/env/jdbc/myAppsPool&quot;
  }
}</pre>
<p>That should solve any of those DataAccessResourceFailureExceptions from now on.[</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dbws.net/blog/2010/02/15/grails-2-dataaccessresourcefailureexception-solved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

