Reputation: 2114
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?
Upvotes: 2
Views: 2857
Reputation: 705
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
Upvotes: 5