Maniram
Maniram

Reputation: 179

is it possible to get jdbc configuration variables in jmeter

I have multiple JDBC Configurations set for different DBs in JMeter. Now i would like to use one of the configurations in a BeanShell to fetch some data programatically.

Is it possible to fetch JDBC Configuration parameters like 'Database URL', 'JDBC Driver class', 'Username', 'Password' using 'Variable Name' set in the JDBC Configuration element? JDBC Configuration element

Upvotes: 1

Views: 784

Answers (1)

Dmitri T
Dmitri T

Reputation: 168197

It is, check out DatabaseMetaData class

Example code:

import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;

Connection conn = DataSourceElement.getConnection("ABC");

DatabaseMetaData meta = conn.getMetaData();

log.info("URL: " + meta.getURL());
log.info("Driver class: " + meta.getDriverVersion());
log.info("Username: " + meta.getUserName());
//etc. 

I don't have Oracle to play with, but I believe it'll work there as well:

JDBC from Beanshell

See How to Use BeanShell: JMeter's Favorite Built-in Component article for more information on using JMeter and Java APIs from Beanshell test elements.

Upvotes: 3

Related Questions