3:在SoapUI的Test Case中新建Groovy Script连接数据库

接口如下

def sql = Sql.newInstance(

地址,

用户名,

密码,

驱动 )

实现样例如下:

import groovy.sql.Sql
//通过读取配置文件连接数据库
 def DBProperties = testRunner.testCase.getTestStepByName( "DBProperties" );
def sql = Sql.newInstance(DBProperties.getPropertyValue( "connection-url" ),DBProperties.getPropertyValue( "sysdb-user-name" ),
           DBProperties.getPropertyValue( "sysdb-password" ),DBProperties.getPropertyValue( "driver-class" ))

 //def sql = Sql.newInstance("jdbc:mysql://localhost:3306/test","root","XXXXX","com.mysql.jdbc.Driver")

4:在SoapUI中通过Groovy脚本操作数据库

1)删除和新建表

//删除表
try {
   sql.execute("drop table PERSON")
} catch(Exception e){}

//新建表
sql.execute('''create table PERSON (
    id integer not null primary key,
    firstname varchar(20),
    lastname varchar(20),
    location_id integer,
    location_name varchar(30)
)''')

2)插入记录

插入记录有两种方式

//向表中插入记录

sql.execute("insert into PERSON (id,firstname,lastname,location_id,location_name) values (1,'gao','shuaihong',1,'hshen') ")

//插入记录另外一种方式
def people = sql.dataSet("PERSON")
people.add( firstname:"James", lastname:"Strachan", id:4, location_id:10, location_name:'London' )

3)查询记录

//选择一行记录
def gaoshuaihong = sql.firstRow("select * from PERSON where id = 1") 
log.info(gaoshuaihong.firstname)

//选择多条记录
def allPerson  = sql.rows(" select * from  PERSON")
log.info(allPerson)
log.info(allPerson[0])
sql.eachRow("select * from PERSON"){ row ->  
    log.info(row.lastname)
 }

4)校验结果
 assert allPerson[0].lastname== "shuaihong"

另外通过Groovy的Sql还支持操作存储过程.

Soap UI 数据库脚本(转)的更多相关文章

  1. Entity Framework Model First下改变数据库脚本的生成方式

    在Entity Framework Model First下, 一个非常常见的需求是改变数据库脚本的生成方式.这个应用场景是指,当用户在Designer上单击鼠标右键,然后选择Generate Dat ...

  2. soap ui 进行接口测试

    [前置条件] 1. 电脑上已安装soap UI 5.0 2. 电脑上已安装eclipse. JDK1.6.tomcat 3. eclipse已经成功的配置JDK1.6.tomcat [操作步骤] 1. ...

  3. Linux下如何将数据库脚本文件从sh格式变为sql格式

    在从事软件开发的过程中,经常会涉及到在Linux下将数据库脚本文件从sh格式变为sql格式的问题.本文以一个实际的脚本文件为例,说明格式转换的过程.        1. sh文件内容 本文中的文件名为 ...

  4. wsse:InvalidSecurity Error When Testing FND_PROFILE Web Service in Oracle Applications R 12.1.2 from SOAP UI (Doc ID 1314946.1)

    wsse:InvalidSecurity Error When Testing FND_PROFILE Web Service in Oracle Applications R 12.1.2 from ...

  5. PowerDesigner中在生成的数据库脚本中用name列替换comment列作为字段描述的方法

    1 PowerDesigner中在生成的数据库脚本中用name列替换comment列作为字段描述的方法如下, 依次打开Tools -- Execute Commands -- Run Script,运 ...

  6. 权限开发 spring security 3.0.7 序列1 数据库脚本

    spring  security  3 细粒度权限控制第一篇,关于权限的初始化测试数据库脚本. 空间脚本: drop user FrameworkTest cascade; drop tablespa ...

  7. ABP+AdminLTE+Bootstrap Table权限管理系统第二节--数据库脚本

    第一点,上一篇文章中我们讲到codefirst中一些问题包括如图 1,codefirst在执行的数据库迁移过程中产生了很多文件,对于强迫症的我而言特别不爽,这些是可以不用生成的啊 2,在codefir ...

  8. ABP+AdminLTE+Bootstrap Table权限管理系统第二节--在ABP的基础做数据库脚本处理

    返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 第一点,上一篇文章中我们讲到codefirst中一些问题包括如图,codefirst在每次执行命令的时候会生成新的 ...

  9. 【C#】数据库脚本生成工具(二)

    年C#研发的数据库文档生成工具,给之后的工作带来了便利.近日,又针对该工具,用WinForm开发了数据库脚本生成工具-DbExcelToSQL. 下面数据库文档生成工具效果图: 感兴趣的朋友可以看下[ ...

随机推荐

  1. jQuery队列控制方法详解queue()/dequeue()/clearQueue()

    queue(name,[callback]):  当只传入一个参数时, 它返回并指向第一个匹配元素的队列(将是一个函数数组,队列名默认是fx);$('#demo').queue('name') 当有两 ...

  2. 配置 Struts2 Hello World

    http://javaweb.group.iteye.com/group/wiki/1505-struts2-under-helloworld---how-to-make-the-first-of-t ...

  3. lispbox 安装运行.sh的时候出现 lispbox.sh: 2: lispbox.sh: Bad substitution

    安装lispbox时使用tar命令将压缩文件解压之后cd进入之后在运行.sh文件时出现了如下情况. $ sh lispbox.sh lispbox.: lispbox.sh: Bad substitu ...

  4. ACE 6.2.0 win7_64 编译

    Windows平台 ~ Microsoft Visual Studio 1)        下载ACE源码 ACE官方网址:http://www.cs.wustl.edu/~schmidt/ACE.h ...

  5. jquery点击其他地方隐藏div层的实现程序

    js代码 $(document).ready(function() { //语言头部的点击事件,显示语言列表 $(".language_selected").click(funct ...

  6. ubuntu漂亮主题

    桌面看腻了?试试这 4 款漂亮的 Linux 图标主题吧 http://linux.cn/article-4332-1.html Flatabulous https://github.com/anmo ...

  7. IdTCPServer, idTCPClient

    IdTcpServer uses IdContext //需要引用 属性,方法: IdTCPServer.Active :=True; //开启服务器 IdTCPServer1.Bindings.Ad ...

  8. AJAX技术的核心

    //创建一个XMLHttpRequest对象 ,利用此对象与服务器进行通信 是AJAX技术的核心 /** * 获取XmlHttpRequest对象 */ function getXMLHttpRequ ...

  9. Provider Communication with Apple Push Notification Service

    This chapter describes the interfaces that providers use for communication with Apple Push Notificat ...

  10. CSS3制作下拉菜单

    导航菜单其实是没有什么可说的,制作方法到处可见,今天这个案例本来不只是一个导 航,还有一个搜索表单的,可是为了偷懒,把搜索表单部分去掉了,就变成了一个CSS3 制作的下拉菜单.在这个导航中主要两点,一 ...