import java.io.FileWriter
import java.io.Writer
import java.util.Random
import java.util.Arrays
FileWriter fstream = new FileWriter("D:\\Jmeter\\测试集_rita\\添加产品.csv",false)
// 1. 设置为true时,从第2行开始插入数据;设置为false时,从第一行开始插入数据。
// 2. 设置为true时,后面运行时不会覆盖原先的数据;设置为false时,会覆盖原先的数据。
BufferedWriter out = new BufferedWriter(fstream)
Object result=vars.getObject("pro_res")
log.info("结果是"+ result)
int len = result.size()
log.info("个数是"+ len)
String p_ids=""
String p_types=""
String p_grades=""
String p_commerce_types=""
String p_air_conditioning_types=""
for(int i=0i<leni++){
String p_id= result.get(i).get("product_id").toString()
String p_type=result.get(i).get("product_types").toString()
String p_type2 = p_type.replace(","," ") //写入文件时是以“,”区分单元格的,所以得替换原先的符号
String[] p_type3 = p_type2.split(" ")
String p_grade= result.get(i).get("grades").toString()
String p_grade2=p_grade.replace(","," ")
String[] p_grade3 = p_grade2.split(" ")
String p_commerce_type= result.get(i).get("commerce_types").toString()
String p_commerce_type2=p_commerce_type.replace(","," ")
String[] p_commerce_type3 = p_commerce_type2.split(" ")
String p_air_conditioning_type=result.get(i).get("air_conditioning_types").toString()
String p_air_conditioning_type2=p_air_conditioning_type.replace(","," ")
String[] p_air_conditioning_type3 = p_air_conditioning_type2.split(" ")
log.info("p_ids为" + p_id)
log.info("p_types为" + p_type2)
log.info("p_grades为" + p_grade2)
log.info("p_commerce_types为" + p_commerce_type2)
log.info("p_air_conditioning_types为" + p_air_conditioning_type2)
log.info("长度为" + p_type3.length)
log.info("长度为" + p_grade3.length)
log.info("长度为" + p_commerce_type3.length)
log.info("长度为" + p_air_conditioning_type3.length)
Random random = new Random()
int i = random.nextInt(p_type3.length)
int j = random.nextInt(p_grade3.length)
int k = random.nextInt(p_commerce_type3.length)
int l = random.nextInt(p_air_conditioning_type3.length)
out.write(p_id + ",")
if (p_type3.length == 1){
out.write(null + ",")//当属性为空时,需要传null
}else{
out.write(p_type3[i].toString() + ",")
}
if (p_grade3.length == 1){
out.write(null + ",")
}else{
out.write(p_grade3[j].toString() + ",")
}
if (p_commerce_type3.length == 1){
out.write(null + ",")
}else{
out.write(p_commerce_type3[k].toString() + ",")
}
if (p_air_conditioning_type3.length == 1){
out.write(null + ",")
}else{
out.write(p_air_conditioning_type3[l].toString() + ",")
}
}
out.close()
fstream.close()
在线程组中添加JDBC Connection Configuration
a.variable Name 中填写的JDBC Request需要引用的值(例如:test)
b.Database URL 中填写jdbc:mysql://数据库的地址:端口号/数据库名称
c.JDBC Driver class中填写:org.gjt.mm.mysql.Driver
d.Username中填写数据库的用户名
e.Password中填写数据库的密码
在测试计划中导入sql所需要的jar包"mysql-connector-java-5.1.20.jar"
添加JDBC Request
a.在variable Name中填入上面说的"test"
b.在Query中填写你所需要 *** 作的sql语句
添加查看结果数后运行查看你 *** 作的接口
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)