Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you are planning <a href="http://docs.codehaus.org/display/GROOVY/Tutorial+6+-+Groovy+SQL" rel="nofollow noreferrer">to do your own sql</a> (like it seems to be the case) over 2 datasources, I suggest that you define your 2 datasources as Spring beans in grails-app/conf/spring.</p> <p>e.g. (drop your db drivers in /lib and replace the values to match your RDBMS drivers and connection string) :</p> <pre><code>import org.apache.commons.dbcp.BasicDataSource import oracle.jdbc.driver.OracleDriver beans = { worksDataSource(BasicDataSource) { driverClassName = "oracle.jdbc.driver.OracleDriver" url = "jdbc:oracle:thin:@someserver:someport:works" username = "works" password = "workspassword" } testDataSource(BasicDataSource) { driverClassName = "oracle.jdbc.driver.OracleDriver" url = "jdbc:oracle:thin:@someserver:someport:test" username = "test" password = "testpassword" } } </code></pre> <p>Then create a service to handle your queries, like :</p> <pre><code>import groovy.sql.Sql class SomeService { def worksDataSource def testDataSource def query1 = """ SELECT crf_name, crf_id FROM works.crfs """ def query2 = """ SELECT group_id, group_name FROM test.item_groups """ def sqlWorks = Sql.newInstance(query1) def sqlTest = Sql.newInstance(query2) // Then do whatever you like with the results of the 2 queries // e.g. sqlWorks.eachRow{ row -&gt; def someDomainObject = new SomeDomainObject(prop1 : row.crf_name, prop2 : crf_id) someDomainObject.otherProp = whateverYouLike() someDomainObject.save() } } </code></pre> <p>Your query doesn't have a where clause so I don't know how you want to relate the data coming from your 2 tables...</p> <p>If you want to do a single query mixing tables from 2 databases, (ask your DBA to) establish a DBLink between databases test and works and perform the query on the datasource containing the DBLink.</p> <p>I hope this helps.</p>
 

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