使用 SoapUI JBDC 请求执行 SQL 服务器过程

Execute a SQL Server Procedure using SoapUI JBDC Request

我想使用 JDBC 请求从 SoapUI 执行 SQL 过程,但没有成功。当我 运行 在 SQL 服务器上执行相同的脚本时,它给我带来了正确的结果。

我成功地使用 JDBC 和简单的 SELECT 句子做了很多测试,但程序没有。

我也尝试使用一些 Groovy 脚本 - 失败。在 SmartBear 文档和社区中搜索,仅找到 SELECT 个示例。

谢谢大家

SmartBear 支持论坛上有很多人面临同样的问题。有时存储过程 returns 更新行数,有时什么也没有。大多数人最终求助于 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(),returns一个结果集:

def result = []
sql.eachRow('call schemaname.show_contacts()') {
   result << "$it.contact_name $it.phone_number"
}

可能比 JDBC 测试步骤更容易。

当使用命令 SET NOCOUNT ON 时,可以执行 JDBC 中的过程。

例子

enter image description here