6

How to parametrize Database URL under JDBC Connection Configuration? Normal parametrization is not working here.

This doesn't work:

Database URL: jdbc:mysql://${mysql_hostname}:${mysql_port}/${mysql_database}
JDBC Driver Class: com.mysql.jdbc.Driver
Username: ${mysql_username}
Password: ${mysql_username}
James Z
  • 12,209
  • 10
  • 24
  • 44
Nelly
  • 137
  • 2
  • 10
  • What do you mean by **Normal parametrization**? and what error you get? – Sabir Khan Jun 16 '17 at 05:05
  • I have hit the same wall here. The variables are not replaced inside `JDBC Connection Configuration` elements. I someone has found a workaround, let me know. – user2173353 Mar 21 '19 at 08:33

3 Answers3

3

The point is that JDBC Connection Configuration test element is being initialized before JMeter Variables so if you want to parameterize it you should be doing it a little bit differently to wit:

  • Use __P() function where required like:

    Database URL: jdbc:mysql://${__P(mysql_hostname,)}:${__P(mysql_port,)}/${__P(mysql_database,)}
    JDBC Driver Class: com.mysql.jdbc.Driver
    Username: ${__P(mysql_username,)}
    Password: ${__P(mysql_password,)}
    

The relevant JMeter Properties can be set either in user.properties file like:

mysql_hostname=localhost
mysql_port=3306
mysql_database=test
mysql_username=johndoe
mysql_passowrd=secret

Or via -J command-line argument like:

jmeter -Jmysql_hostname=localhost -Jmysql_port=3306 -Jmysql_database=test -Jmysql_usename=johndoe -Jmysql_password=secret

See Apache JMeter Properties Customization Guide for more information on JMeter Properties and ways of setting and overriding them

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • this fine for running from command line but not for the gui. Which is frustrating because thats when you want to set the development values – Justin Aug 01 '18 at 04:15
  • This is sad. Any way to modify the JDBC Configuration after it gets created (with groovy code)? It would be super nice if we could configure its properties based on CSV files and not parameters. – user2173353 Mar 21 '19 at 08:59
1

in Jmeter (5.1.1) you can use 'User Defined Variables'. Add-> Config Element -> User Defined Variables.

1) Provide User Defined Variables, like, db host, db port, user name, password...

2)create JDBC Connection Configuration, and use defined variables

3)do your JDBC Request

4) Check results

Robby
  • 381
  • 2
  • 3
0

It really would be nice to be able to have the DB Connection initialize AFTER the JMeter variables. I have a JMeter JMX that calls a DB stored proc. I call the JMX through Jenkins automation.

I do the same call on multiple DBs. It would be soooo much easier to call the JMX once from Jenkins and use a CSV file to have it run against the multiple DBs than it would be to have to make the call multiple times in the Jenkins file and pass in a different DB name for each call.

Also, when I need to run this against yet another DB, it it a lot easier to add the new DB to a CSV file than it is to add yet another call to the Jenkins file.

There are possible workarounds in the Jenkins file, but none work as good or are as simple as being able to set the JDBC connection setting from a CSV file in the JMeter JMX itself.

Ray D
  • 11
  • 3