SOAPUI & Groovy Scripts, executing multiple SQL statements in one go

…衆ロ難τιáo~ 提交于 2019-12-01 22:38:05

Couldn't you just store them in the properties file with the semicolons, then remove them after reading them, e.g.

String sqlProperty = // read SQL property from file
def statements = sqlProperty.split(";")

// Execute each statment using conn (an instance of groov.sql.Sql?)
statements.each { conn.execute(it);

Some JDBC drivers support multiple statements and this functionality will then be available via Groovy's Sql class, e.g. with MySql:

def props = [user: 'myuser', password: 'mypassword', allowMultiQueries: 'true'] as Properties
def url = 'jdbc:mysql://127.0.0.1:3306/mydb'
def driver = 'com.mysql.jdbc.Driver'
def sql = Sql.newInstance(url, props, driver)
sql.execute """
  insert into PERSON (id, firstname, lastname) values (1, 'Dierk', 'Koenig');
  insert into PERSON (id, firstname, lastname) values (2, 'Guillaume', 'Laforge');
  insert into PERSON (id, firstname, lastname) values (3, 'Jon', 'Skeet');
"""
ripper234

Sometimes that's not good enough. Check out my solution: Running multiple SQL statements from Groovy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!