title: should pooled=true or pooled=false for Grails using tomcat database resource via JNDI
body: <p>When you use Grails to manage the MySQL connection, you need (in order to handle reconnections) a properties section along the lines of this in your DataSource.groovy:</p>
  
  <pre><code>dataSource {
      pooled = true
      driverClassName = "com.mysql.jdbc.Driver"
      dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
      properties {
          maxActive = -1
          minEvictableIdleTimeMillis=1800000
          timeBetweenEvictionRunsMillis=1800000
          numTestsPerEvictionRun=3
          testOnBorrow=true
          testWhileIdle=true
          testOnReturn=true
          validationQuery="SELECT 1"
      }
  
  environments {
      production{
          dataSource {
              dbCreate = "upate"
              url = "jdbc:mysql://127.0.0.1:3306/mydb"
              username = "myuser"
              password = "mypass"
          }
  
      }
  </code></pre>
  
  <p>When you switch to using Tomcat's connection pool, most examples give this:</p>
  
  <pre><code>production {
      dataSource {
          dbCreate = "update"
          jndiName = "java:comp/env/revolve"
      }
  </code></pre>
  
  <p><strong>Question 1</strong></p>
  
  <p>Should pooled=true or false in DataSource.grovvy for this type of connection (i.e. using tomcat), or does it matter?  There are posts saying it must be false, posts saying it must be true, and some not specifying it.  If set to True, this implies that there is a pool of pools, but this is what most examples are recommending.</p>
  
  <p><strong>Question 2</strong></p>
  
  <p>Is the properties section ignored?  If not, what are the recommended fields to be set.  From my trial and error, properties seem to be being ignored, contrary to posts like <a href="https://stackoverflow.com/questions/23062082/best-mysql-datasource-properties-for-grails-tomcat-jndi">this one</a>.</p>
  
  <p>E.g. the validationQuery="SELECT 1" in the DataSource.java properties seems to be being ignored when using JNDI.  I.e. if I restart the DB, the app on Tomcat has permanently lost its connection to the DB.  If I add this same line in the Tomcat context.xml thusly:</p>
  
  <pre><code>&lt;Resource name="revolve" auth="Container" type="javax.sql.DataSource"
      maxActive="50" maxIdle="5" maxWait="10000"
      username="myuser" password="mypass" driverClassName="com.mysql.jdbc.Driver"
      validationquery="SELECT 1;"
      url="jdbc:mysql://127.0.0.1:3306/mydb"/&gt;
  </code></pre>
  
  <p>and restart Tomcat, now if I restart the DB, the app on Tomcat continues to run.</p>
  
  <p>This implies that the properties section of the dataSource in DataSource.groovy are being ignored when using Tomcat's connection pool.</p>