title: Using two databases for an application in grails
body: <p>I am creating an application in grails that should read from one database and write into another database. I have created datasources.groovy for this requirement and have installed the datasources plugin. However, I am stuck at how to use this datasource when executing an sql query (select * from........etc. etc).</p>
  
  <p>For eg. Below is how I run a query in my action. I am using customized queries and not gorm.</p>
  
  <p>EDITED:</p>
  
  <pre><code>class TuneController {   
  
      def dataSource_ds2
  
      def list = {
  
          String nameSql = "select name from emp where id=3345"
          Sql sql = new Sql(dataSource_ds2)
          String name = sql.rows(nameSql)
          println(name)
      }
  }
  </code></pre>
  
  <p>In the above case, datasources is not read and has a null value. 
  Is there any sample code available for this requirement.</p>
  
  <p>Am I missing something here?</p>
  
  <p>EDIT:</p>
  
  <p>My Datasources.groovy entry is as below.</p>
  
  <pre><code>datasources = { 
  
      datasource(name:'ds2') {
          domainClasses([com.Tune])
          readOnly(true)
          driverClassName('oracle.jdbc.driver.OracleDriver')
          url('jdbc:oracle:thin:@test-ofr.wellmanage.com:1521:OFRS1')         
          username('test')
          password('test')
          environments(['development'])
          dbCreate('do-not-bother')
          logSql(true)
          dialect(org.hibernate.dialect.Oracle10gDialect)
          hibernate {
              cache {
                  use_second_level_cache(false)
                  use_query_cache(false)
              }
          }
      }
  }
  </code></pre>