SmartBear 支持论坛有很多关于面临同样问题的人的帖子。有时存储过程返回更新的行数,有时什么也不返回。大多数人最终都求助于 Groovy。
所以,下面是一个调用存储过程schemaname.calcs 的示例,该过程接受两个整数 IN 参数和四个整数 OUT 参数:
import groovy.sql.Sql
def url = 'full JDBC URL' // e.g. 'jdbc:sqlserver://127.0.0.1:1433/database'
def user = 'username'
def password = ''
def driver = 'driver class'
def sql = Sql.newInstance(url, user, password, driver)
sql.call( "{call schemaname.calcs(?, ?, ?, ?, ?, ?)}", [ 10,2, Sql.INTEGER , Sql.INTEGER, Sql.INTEGER, Sql.INTEGER],
{ outParameter1, outParameter2, outParameter3, outParameter4 ->
log.info("Result 1 '${outParameter1}'")
log.info("Result 2 '${outParameter2}'")
log.info("Result 3 '${outParameter3}'")
log.info("Result 4 '${outParameter4}'")
})
sql.close()
或者,调用返回结果集的存储过程schemaname.show_contacts():
def result = []
sql.eachRow('call schemaname.show_contacts()') {
result << "$it.contact_name $it.phone_number"
}
可能比使用 JDBC 测试步骤更容易。