简体   繁体   中英

Using a JMeter JDBC connection in Java code

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?

Suppose you have the following JDBC Connection Configuration configuration:

在此输入图像描述

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

在此输入图像描述

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM