JMeter使用JDBC Request取样器 获取查询结果

  • JDBC获取查询结果
  • Java脚本创建文件
  • JSON字符串解析
  1. 数据库连接配置
  2. 定义全局变量
  3. JDBC Request

创建文件路径以及文件的脚本

import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
boolean result = false;
try {
    //String message= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis()));
    String message = vars.get("abc");
    //String message= String.valueOf(2);
    SimpleDateFormat formatter= new SimpleDateFormat("yyyyMMddHHmmss");
    Date date = new Date(System.currentTimeMillis());
    System.out.println(formatter.format(date));
    String logfile = vars.get("log");
    File folder = new File(logfile);
    File file = new File(folder.getPath()+"\\"+formatter.format(date)+".log");
    if(folder.exists() && file.createNewFile()) { result=true; }
    else if(folder.mkdir()&&file.createNewFile()) { result=true; }
    if(result)
    {
        FileOutputStream out = new FileOutputStream(file);
        byte[] bytes = message.getBytes();
        out.write(bytes);
        out.close();
        SampleResult.setSuccessful(true);
    }
    else
    {
        SampleResult.setSuccessful(false);
    }
}catch (Exception e){
    e.printStackTrace();
    SampleResult.setSuccessful(false);
}

参考网址

Java json与object互转【Java json与object互转_jsonobject转object_java后生的博客-CSDN博客
java如何判断文件或文件夹是否存在?【https://blog.csdn.net/weixin_45987729/article/details/124503383
jmeter连接数据库-取数据【https://blog.csdn.net/weixin_40385652/article/details/115490432
Jmeter常见使用方法【https://blog.csdn.net/weixin_41923467/article/details/127206795】【https://blog.csdn.net/qq_45138120/article/details/124056704
使用JMeter进行MySQL的压力测试,对查询结果进行简单处理【https://zhuanlan.zhihu.com/p/551932532?utm_id=0
【性能测试】JMeter(二)--进阶篇(提取多个值并遍历使用【https://blog.csdn.net/qq_35061334/article/details/123599146
Java Object转JSONObject,ArrayList,取值【https://blog.csdn.net/qqqwwweeerasd/article/details/124629234

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值