Sandeep Sharma
Sandeep Sharma

Reputation: 109

JMeter Groovy SQL Connection use JDBC Connection Configuration

I have set up the JDBC Connection Configuration in JMeter

Now I would like to use this connection details across all JSR223 Sampler using groovy code but I am getting an error or really don't know how to use it

So instead of being able to simply use the connection configuration I am providing the full connection string details in each sampler

import groovy.sql.Sql

def dburl = 'jdbc:mysql://${__P(${env}_host)}:${__P(${env}_port)}/${__P(${env}_db)}?requireSSL=false&useSSL=false&rewriteBatchedStatements=true&useServerPrepStmts=true&verifyServerCertificate=false'
def user = '${__P(${env}_username)}'
def password = '${__P(${env}_password)}'
def driver = '${__P(${env}_driver)}'

def sql = Sql.newInstance(dburl, user, password, driver)

How can I simply used the connection configuration I created

enter image description here

Upvotes: 1

Views: 938

Answers (1)

Dmitri T
Dmitri T

Reputation: 168122

Something like:

def connection = org.apache.jmeter.protocol.jdbc.config.DataSourceElement.getConnection("your pool name")
def sql = new Sql(connection)

Also don't use JMeter Functions or Variables in Groovy scripts.

More information: Apache Groovy - Why and How You Should Use It

Upvotes: 3

Related Questions