An attempt to use named parameters for calls to Oracle stored procedures. The in parameters work fine, but I cannot access the out parameters.
The code for the test stored procedure is at the bottom of the page.
import groovy.util.GroovyTestCase
import groovy.sql.Sql
import lib.*
import java.sql.*
import oracle.jdbc.*
def sql;
this.class.classLoader.rootLoader.addURL(new URL("file:ojdbc7.jar"))
sql= Sql.newInstance ("jdbc:oracle:thin:@......", "..user..", "..password..")
The following example works fine using? placeholders
def greeting
println "**** Example 1 ****\n"
sql.call "{call groovy_test(?,?)}",
[ 'Johny', Sql.VARCHAR ],
{ dbgreeting -> greeting = dbgreeting }
println "greeting: " + greeting
The following example does not work with an invalid column type
/*** Example 2 ***/
def greeting2
println "\n**** Example 2 ****\n"
sql.call "{call groovy_test(:myname,:greeting)}",
[ myname:'Johny', greeting:Sql.VARCHAR ],
{ dbgreeting -> greeting2 = dbgreeting }
println "greeting: " + greeting
/* Error
groovy.sql.Sql call
WARNING: Failed to execute: {call groovy_test(:myname,:greeting)} because: Invalid column type
Caught: java.sql.SQLException: Invalid column type
*/
There are no results in the following example.
def greeting3
println "\n**** Example 3 ****\n"
sql.execute "{call groovy_test(:myname,:greeting)}",
[ myname:'Johny', greeting:Sql.VARCHAR ],
{ dbgreeting -> greeting3 = dbgreeting }
println "Test3 greeting: " + greeting3
Does anyone have an idea on how to access out parameters when using a name with a name? More complex procedures are executed, and they get input values. This has been verified in the table data.
Stored Procedure Code:
create procedure groovy_test( myname varchar2, greeting out varchar2 )
as
begin
greeting := 'hello ' || myname;
end;