借助数据库执行sql语句批量生成测试数据
2017-05-10 18:49
519 查看
本人在学习selenium2java和数据库使用的过程中,需要测试兑换卡购买课程的功能。测试的兑换卡之前都是手动添加的比较麻烦,自己写了一个方法,批量生成测试兑换卡。
//添加兑换卡
public static void addCoupon() throws ClassNotFoundException, SQLException {
String coupon_id;
String serial_password = "CcPCbKffbC0da390c3c77bmmPmdmaF9C";
String coupon_type = "2";
String effective_date = "2017-12-31 23:59:59";
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, user, password);
if (!connection.isClosed()) {
Statement statement = connection.createStatement();
for(int i=10;i<100;i++){
coupon_id = "000000001"+i;
String sql = "INSERT INTO op_coupon (serial_no,serial_password,coupon_type,effective_date) VALUES ('"+coupon_id+"','"+serial_password+"','"+coupon_type+"','"+effective_date+"')";
// output(sql);
statement.executeUpdate(sql);
}
connection.close();
}
这里需要注意的是,测试卡号是“0”打头的,不可以直接使用数据类型转化来设置兑换卡号,需要用到字符串的拼接。
//添加兑换卡
public static void addCoupon() throws ClassNotFoundException, SQLException {
String coupon_id;
String serial_password = "CcPCbKffbC0da390c3c77bmmPmdmaF9C";
String coupon_type = "2";
String effective_date = "2017-12-31 23:59:59";
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, user, password);
if (!connection.isClosed()) {
Statement statement = connection.createStatement();
for(int i=10;i<100;i++){
coupon_id = "000000001"+i;
String sql = "INSERT INTO op_coupon (serial_no,serial_password,coupon_type,effective_date) VALUES ('"+coupon_id+"','"+serial_password+"','"+coupon_type+"','"+effective_date+"')";
// output(sql);
statement.executeUpdate(sql);
}
connection.close();
}
这里需要注意的是,测试卡号是“0”打头的,不可以直接使用数据类型转化来设置兑换卡号,需要用到字符串的拼接。
相关文章推荐
- 应用Druid监控SQL语句的执行情况(测试数据表明,Druid性能比DBCP、C3P0、Proxool、JBoss都好)
- 安卓开发SQlite使用执行SQL语句一些简单的处理——2.查询数据库的数据
- 批量更改数据库表架构(生成sql后直接执行!)
- 把excel数据生成sql插入数据库语句
- ASP.NET基础教程-使用CommandBuilder对象自动生成SQL语句对数据进行批量更新
- navicat 导出向导 , 通过Excel生成批量SQL语句,处理大量数据
- CommandBuilder对象自动生成SQL语句对数据进行批量更新(单表)
- 向数据库中批量插入数据的sql 语句
- 在MySQL命令行窗口执行sql脚本,批量执行SQL语句,批量更新数据
- 通过Excel生成批量SQL语句,处理大量数据的好办法
- discuz论坛用sql语句批量插入测试数据(百万级别)
- 处理数据批量生成sql插入语句
- [MyBatis]获取数据库连接、批量执行SQL语句
- 如何检测mysql 数据库执行了哪些sql语句 ecshop如何添加商品属性 ecshop 商品属性批量采集入库
- python脚本批量生成50000条插入数据的sql语句
- mybatis执行查询语句查询不到结果,控制台输出sql语句复制到数据库中能查到数据
- C# 执行多条SQL语句,实现数据库事务(通过Hashtable存储数据) .
- 安卓开发SQlite使用执行SQL语句一些简单的处理——1.创建数据库,表和添加数据
- Excel拼装Sql语句将数据批量导入数据库
- 处理数据批量生成sql插入语句