代码之家  ›  专栏  ›  技术社区  ›  SnowBG

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

  •  0
  • SnowBG  · 技术社区  · 7 年前

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

    我成功地使用JDBC和简单的SELECT语句进行了很多测试,但过程没有成功。

    我还尝试使用一些Groovy脚本-Fail。在SmartBear docs和community上搜索并仅选择示例。

    谢谢大家。

    enter image description here

    2 回复  |  直到 7 年前
        1
  •  2
  •   craigcaulfield    7 年前

    SmartBear支持论坛有很多线程,人们面临着相同的问题。有时存储过程返回更新的行数,有时返回空。大多数人最终求助于Groovy。

    下面是一个调用存储过程的示例 schemaname.calcs 取两个整数输入参数和四个整数输出参数:

    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测试步骤更容易。

        2
  •  2
  •   Marina Moraes    7 年前

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

    实例

    enter image description here