I am trying to call a stored procedure through groovy in ReadyAPI. I am doing it this way, because the built in JDBC request does not seem to handle INOUT parameters.
The call seems like it works, but it doesn't actually make the call from what I can tell. One of the parameters is an INOUT parameter and after the call, I just get back what I passed in. There is supposed to be a conversion of the value passed. Also, there is some database logging that should happen that is not. However, the 2 OUT parameters are returned as expected. If I take the same call from the script and run it in a database tool, everything works as expected, so there is not an issue with the stored proc itself.
Here is the code from groovy script:
import groovy.sql.Sql
def globalUser = context.expand('${#Global#Username}')
def globalPassword = context.expand('${#Global#Password}')
def sql = Sql.newInstance("jdbc:as400://server/library", globalUser, globalPassword, "com.ibm.as400.access.AS400JDBCDriver")
sql.call("{call sp_storedproc('inparm1', 'inparm2', 'inparm3', 'inparm4', ${Sql.inout(Sql.VARCHAR('inout5'))}, ${Sql.VARCHAR},${Sql.VARCHAR})}") { parm5, parm6, parm7->
log.info parm5
log.info parm6
log.info parm7
}
I have also tried calling the stored procedure like this, but I always get data type mismatch errors. I don't know what the real difference is.
sql.call '{call storedproc(?,?,?,?,?,?,?)}',
["inparm1", "inparm2", "inparm3", "inparm4", "${Sql.inout(Sql.VARCHAR('inout5'))}", "${Sql.VARCHAR}", "${Sql.VARCHAR}"]
Error message for Data Mismatch:
Wed Jun 21 08:46:01 EDT 2017:ERROR:java.sql.SQLException: Data type mismatch.
java.sql.SQLException: Data type mismatch.
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:385)
at com.ibm.as400.access.SQLChar.set(SQLChar.java:152)
at com.ibm.as400.access.AS400JDBCPreparedStatement.setValue(AS400JDBCPreparedStatement.java:3173)
at com.ibm.as400.access.AS400JDBCPreparedStatement.setObject(AS400JDBCPreparedStatement.java:2640)
at groovy.sql.Sql.setObject(Sql.java:4137)
at groovy.sql.Sql.setParameters(Sql.java:4102)
at groovy.sql.Sql.call(Sql.java:3007)
at groovy.sql.Sql$call$3.call(Unknown Source)
at Script13.run(Script13.groovy:28)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SoapUIProGroovyScriptEngineFactory.java:79)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:156)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Thanks in advance for any help.