Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3356792
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:33:20+00:00 2026-05-18T02:33:20+00:00

I am creating an application in grails that should read from one database and

  • 0

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).

For eg. Below is how I run a query in my action. I am using customized queries and not gorm.

EDITED:

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)
    }
}

In the above case, datasources is not read and has a null value.
Is there any sample code available for this requirement.

Am I missing something here?

EDIT:

My Datasources.groovy entry is as below.

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)
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:33:20+00:00Added an answer on May 18, 2026 at 2:33 am

    The secondary datasources are available using dependency injection, but their names are based on the names in Datasources.groovy. For example if you’ve defined a datasource named ‘foo’, then you would inject that with def dataSource_foo:

    class MyController {
    
       def dataSource_foo
    
       def list = {
          String nameSql = "select name from emp where id=3345"
          Sql sql = new Sql(dataSource_foo)
          def rows = sql.rows(nameSql)
          ...
       }
    }
    

    Note that you must put def dataSource_foo as a class-scope field and not inside your action (or method). This is true for every dependency injection – if it’s inside a method or a closure it’s just a method-scope variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok I creating an application that needs to query records from my remote database.
I am creating an application where I am calling my database from a different
I'm creating an application that will store a hierarchical collection of items in an
I'm currently creating an application for a customer that will allow them to automatically
I am creating an application that manages multiple instances of an external utility, supplying
I am creating an application in .NET that will serve as a second UI
I am creating an application in which I have two mxml components, MainPanel.mxml and
I've been playing around with creating an application using the S#arp Architecture . One
When creating a web application, and lets say you have a User object denoting
I'm creating an application that notifies users if a new row has been added

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.