Skip to content

JMeter JDBC Database Load Testing Guide

Benchmark database performance with JMeter JDBC: connection pool tuning, prepared statements, callable queries, variable mapping, and latency assertions.

Difficulty
intermediate
Guide type
how-to
Estimated read time
13 min read
Last verified version
Verified JMeter 5.6

Apache JMeter enables direct load testing and performance benchmarking of relational databases (PostgreSQL, MySQL, Oracle, MS SQL Server, MariaDB) using JDBC. This allows performance engineers to isolate database query latency, test connection pool limits, benchmark stored procedures, and validate database performance independently of the application layer.

This guide walks through driver installation, connection pool sizing, parameterized queries, and extracting result sets into JMeter variables.


JMeter does not bundle proprietary database drivers. You must download the appropriate JDBC driver .jar file and place it in JMeter’s lib/ directory, then restart JMeter:

DatabaseDriver Class NameMaven / JAR ArtifactExample Database URL
PostgreSQLorg.postgresql.Driverpostgresql-42.x.jarjdbc:postgresql://localhost:5432/testdb
MySQL / MariaDBcom.mysql.cj.jdbc.Drivermysql-connector-j-8.x.jarjdbc:mysql://localhost:3306/testdb?useSSL=false
Oracle DBoracle.jdbc.OracleDriverojdbc8.jar / ojdbc11.jarjdbc:oracle:thin:@//localhost:1521/XEPDB1
MS SQL Servercom.microsoft.sqlserver.jdbc.SQLServerDrivermssql-jdbc-12.x.jarjdbc:sqlserver://localhost:1433;databaseName=testdb;encrypt=true;trustServerCertificate=true

2. Configuring JDBC Connection Configuration

Section titled “2. Configuring JDBC Connection Configuration”

The JDBC Connection Configuration config element defines the connection pool.

  • Variable Name Bound to Pool: e.g., db_pool_main (Must match the Variable Name in your JDBC Request samplers).
  • Max Number of Connections: Maximum concurrent database connections (e.g., 50).
  • Pool Timeout: 10000 (ms) — how long a thread waits if all pool connections are occupied before throwing an error.
  • Idle Timeout: 60000 (ms).
  • Validation Query: Simple query to check connection health before borrowing:
    • PostgreSQL / MySQL: SELECT 1
    • Oracle: SELECT 1 FROM DUAL
  • Transaction Isolation: DEFAULT (or TRANSACTION_READ_COMMITTED).

Add Sampler → JDBC Request under your Thread Group:

  • Variable Name of Pool: db_pool_main
  • Query Type:
    • Select Statement: Standard read queries.
    • Prepared Select Statement: Parameterized read query (prevents SQL injection and improves DB execution plan caching).
    • Prepared Update Statement: INSERT, UPDATE, DELETE operations.
    • Callable Statement: Stored procedure execution.

Example A: Parameterized Prepared Select Statement

Section titled “Example A: Parameterized Prepared Select Statement”
SELECT user_id, email, status, created_at
FROM users
WHERE status = ? AND country = ?
ORDER BY created_at DESC
LIMIT 10;
  • Parameter values: ACTIVE, \${userCountry}
  • Parameter types: VARCHAR, VARCHAR
  • Variable names: userId, userEmail, userStatus, userCreatedAt

When you specify variable names in the Variable names field (e.g., userId, userEmail), JMeter automatically parses the result set into indexed variables:

  • userId_#: Total number of returned rows (e.g., 10).
  • userId_1: First row’s user_id.
  • userId_2: Second row’s user_id.
  • userId_n: nth row’s user_id.

Iterating Over SQL Results with ForEach Controller:

Section titled “Iterating Over SQL Results with ForEach Controller:”
  1. Set Input variable prefix: userId
  2. End index: \${userId_#}
  3. Output variable name: currentUserId
  4. Inside the ForEach loop, make subsequent HTTP calls to /api/users/\${currentUserId}.

5. Benchmark Stored Procedures (Callable Statement)

Section titled “5. Benchmark Stored Procedures (Callable Statement)”
{call process_monthly_invoice(?, ?, ?)}
  • Parameter values: \${accountId}, \${billingCycle}, INOUT
  • Parameter types: INTEGER, VARCHAR, OUT VARCHAR

  1. Size Pool Connections Appropriately: Set Max Number of Connections equal to or greater than the number of active concurrent threads in the Thread Group to prevent threads from blocking on pool locks.
  2. Use Prepared Statements: Always prefer Prepared Select/Update statements over raw SQL strings to allow the database engine to reuse execution plans and avoid parse overhead.
  3. Clean Up Generated Test Data: Use a tearDown Thread Group with a dedicated cleanup query to delete records inserted during test execution.
On this page