您的位置:首页 > 数据库

借助数据库执行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”打头的,不可以直接使用数据类型转化来设置兑换卡号,需要用到字符串的拼接。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐