借助数据库执行sql语句批量生成测试数据

来源:互联网 发布:booking.it 编辑:程序博客网 时间:2024/05/22 01:48

本人在学习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”打头的,不可以直接使用数据类型转化来设置兑换卡号,需要用到字符串的拼接。

0 0
原创粉丝点击