简体   繁体   English

使用SoapUI JBDC请求执行SQL Server过程

[英]Execute a SQL Server Procedure using SoapUI JBDC Request

I'd like to excecute a SQL procedure from SoapUI using JDBC Request but I got no success. 我想使用JDBC Request从SoapUI执行SQL过程,但没有成功。 When I run the same script on SQL Server, it brings me the right result. 当我在SQL Server上运行相同的脚本时,它带给我正确的结果。

I made a lot of tests using JDBC and simple SELECT sentences successfully, but the Procedure don't. 我使用JDBC和简单的SELECT语句成功进行了许多测试,但过程却没有。

I also tried to use some Groovy Script - Fail. 我还尝试使用一些Groovy脚本-失败。 Searched on SmartBear docs and community and found only SELECTs examples. 在SmartBear文档和社区中进行搜索,仅找到SELECTs示例。

Thank you all. 谢谢你们。

在此处输入图片说明

The SmartBear support forums have lots of threads with people facing the same problem. SmartBear支持论坛上的话题很多,人们面临着同样的问题。 Sometimes the stored procedure returns the number of rows updated, sometimes nothing. 有时存储过程返回更新的行数,有时不返回。 Most people end up resorting to Groovy. 大多数人最终都诉诸Groovy。

So, here's an example of calling a stored procedure schemaname.calcs that takes two integer IN parameters and four integer OUT parameters: 因此,这是一个调用存储过程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()

Or, to call a stored procedure schemaname.show_contacts() that returns a result set: 或者,调用返回结果集的存储过程schemaname.show_contacts()

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

Might be easier than battling with a JDBC test step. 比使用JDBC测试步骤容易。

When using the command SET NOCOUNT ON it is possible to execute the procedure in JDBC. 使用命令SET NOCOUNT ON时,可以在JDBC中执行该过程。

example

enter image description here 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM