Can anyone tell me how to call stored procedure from Grails which is present in User-defined path.
For that purpose you can use Groovy Sql
.
To use Groovy SQL:
import groovy.sql.Sql
def dataSource
or def sessionFactory
for transactionsdef sql = new Sql(dataSource)
or def sql = new Sql(sessionFactory.currentSession.connection())
Grails will manage the connection to the datasource automatically.
Note: dataSource
and sessionFactory
are beans that you would have to inject in your pojo/bean class.
So to execute sql code written on your file:
String sqlFilePath = grailsApplication.parentContext.servletContext.getRealPath("/data/proc.sql")
String sqlString = new File(sqlFilePath).text
Sql sql = new Sql(sessionFactory.currentSession.connection())
sql.execute(sqlString)
This will execute any sql statements written in your file on your sql server.