Search code examples
jmeterjmeter-4.0jmeter-3.2jmeter-5.0

How to close JDBC Connection in jmeter


I'm using JDBC connection configuration and JDBC request sampler to fetch test data from database for large set of data for my test requirement. My question is, if we connecting to database through connection configuration and JDBC sampler to fetch data from database then how we can close the connection from database like we are having other performance testing tool Neoload. As of now what i'm seeing from total number of active connections in sql server using sp_who2 or below query is that JDBC connection not closed after jmeter test execution completed. Question is, How to closed JDBC connection if my purpose to use is completed within the script execution? Any help would be appreciated.


Solution

  • If this is something you really need, you can invoke DataSourceElement.getConnection() function from any JSR223 Test Element which will return an instance of java.sql.Connection so you will be able to call Connection.close() function.

    Something like:

    org.apache.jmeter.protocol.jdbc.config.DataSourceElement.getConnection('foo').close()
    

    where foo is your connection pool variable name.

    enter image description here