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.