简体   繁体   中英

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. When I run the same script on SQL Server, it brings me the right result.

I made a lot of tests using JDBC and simple SELECT sentences successfully, but the Procedure don't.

I also tried to use some Groovy Script - Fail. Searched on SmartBear docs and community and found only SELECTs examples.

Thank you all.

在此处输入图片说明

The SmartBear support forums have lots of threads with people facing the same problem. Sometimes the stored procedure returns the number of rows updated, sometimes nothing. Most people end up resorting to Groovy.

So, here's an example of calling a stored procedure schemaname.calcs that takes two integer IN parameters and four integer OUT parameters:

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:

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.

When using the command SET NOCOUNT ON it is possible to execute the procedure in JDBC.

example

enter image description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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