I am working on a Grails application where I must access several datasources. The datasources are defined in the default database (ie. they are stored there and I must make
I worked on similar project where the application has to retrieve list of datasources (connection strings) from the default database, and connect to each datasource and perform operations using quartz jobs.
I implemented it like, connect to each datasource within the application (not from DataSorce.groovy) and write SQL rather tahn HQL.
import groovy.sql.Sql
class SqlService{
Sql getDbConnection(String connectionString, String dbUser, String dbPassword){
def sql = Sql.newInstance(connectionString, dbUser, dbPassword, "driver_class")
return sql
}
}
Get sql
connection from the above code and execute SQL queries using sql.execute "SQL STATEMENT"
and close the sql
connection. Here is the Sql
class documentation.