mbayloon mbayloon - 1 year ago 170
Groovy Question

How can I call a stored procedure using groovy?

  1. how can i call a stored procedure using groovy?

  2. how can i create a stored procedure from grails project (as domain classes to create data base)?

Answer Source

An example of calling a FullName stored procedure which takes a param ('Sam' in the example) and returns a VARCHAR."{? = call FullName(?)}", [Sql.VARCHAR, 'Sam']) { name ->
    assert name == 'Sam Pullara'

The same example again but with a GString variation:

def first = 'Sam'"{$Sql.VARCHAR = call FullName($first)}") { name ->
    assert name == 'Sam Pullara'

Here is an example of a stored procedure with an out parameter: '{call Hemisphere(?, ?, ?)}', ['Guillaume', 'Laforge', Sql.VARCHAR], { dwells ->
    println dwells // => Northern Hemisphere

Refer this.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download