在Java代码中使用JMeter JDBC连接 [英] Using a JMeter JDBC connection in Java code

查看:783
本文介绍了在Java代码中使用JMeter JDBC连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java Request类来在JMeter中使用。该类需要访问由测试计划的其余部分使用的同一数据库。有没有办法从Java代码访问测试计划的JDBC连接?

I'm working on a Java Request class for use in JMeter. The class needs to have access to the same database that's being used by the rest of the test plan. Is there a way to access the test plan's JDBC Connection from Java code?

推荐答案

假设您有以下 JDBC连接配置配置:

< img src =https://i.stack.imgur.com/A2kb3.pngalt =在此处输入图像说明>

您可以通过这种方式访问​​连接使用 JSR223 Sampler + Groovy + Cache Key(无论你想要什么独特的字符串) :

You can access connection this way using a JSR223 Sampler + Groovy+Cache Key (whatever unique String you want):

如果你想复制粘贴,Sampler包含:

If you want to copy paste, Sampler contains this:


import java.sql.Connection;
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
Connection conn = DataSourceElement.getConnection("jdbcConfig");
// Ensure you close conn


这篇关于在Java代码中使用JMeter JDBC连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆