Skip to content

JMeter JDBC Connection Pool & SQL Database Errors

Fix JMeter JDBC Connection Configuration errors: Cannot create PoolableConnectionFactory, Communications link failure, driver setup, and pool exhaustion.

Difficulty
intermediate
Guide type
troubleshooting
Estimated read time
7 min read
Last verified version
Verified JMeter 5.6

JDBC Connection Pool & Database Errors in JMeter

Section titled “JDBC Connection Pool & Database Errors in JMeter”

When running database performance tests using the JDBC Request sampler and JDBC Connection Configuration element, samplers fail in View Results Tree or jmeter.log with:

Response code: 500
Response message: java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure)
The last packet successfully received from the server was 0 milliseconds ago.

Or when database credentials or database names are incorrect:

java.sql.SQLException: Cannot create PoolableConnectionFactory (Access denied for user 'dbuser'@'10.0.0.5')

Or when all connections in the pool are busy:

java.sql.SQLException: Timeout waiting for idle object
at org.apache.commons.dbcp2.PoolableConnectionFactory...

The JDBC Request sampler fails, and database queries are not executed against the database.

  • Cannot create PoolableConnectionFactory: The connection pool failed to establish its initial connection. Check JDBC URL syntax, port numbers, database credentials, or database firewall rules.
  • Timeout waiting for idle object: All database connections in the pool (Max Number of Connections) are currently checked out by active virtual users, and new requests timed out waiting for a connection to be returned.
Error MessageCauseWhy it happens
Communications link failure / Connection refusedDatabase network unreachableDatabase port (3306, 5432, 1521, 1433) closed, blocked by firewall, or DB not listening on external interface
Cannot load JDBC driver classMissing JAR fileJDBC Driver .jar is not placed in JMETER_HOME/lib/ or JMeter was not restarted
Timeout waiting for idle objectConnection pool exhaustedConcurrency exceeds Max Number of Connections with slow-running SQL queries
Access denied for userAuthentication failureIncorrect database username/password or user not permitted from load injector IP
Variable name mismatchConfig element mappingVariable Name Bound to Pool in JDBC Request does not match the name in JDBC Connection Configuration

In JMeter, the JDBC Connection Configuration creates a named pool, and each JDBC Request must specify the exact matching pool name:

  • In JDBC Connection Configuration:
    • Variable Name for created pool: APP_DB_POOL
  • In JDBC Request:
    • Variable Name of Pool declared in JDBC Connection Configuration: APP_DB_POOL

If these names differ by even one character (or case), the request will fail immediately.

2. Configure Correct Driver Class Name and JDBC URL

Section titled “2. Configure Correct Driver Class Name and JDBC URL”

Ensure the driver class and URL format match your database engine:

DatabaseDriver Class NameDatabase URL Format
PostgreSQLorg.postgresql.Driverjdbc:postgresql://localhost:5432/dbname?sslmode=disable
MySQL / MariaDBcom.mysql.cj.jdbc.Driverjdbc:mysql://localhost:3306/dbname?useSSL=false&serverTimezone=UTC
Oracleoracle.jdbc.OracleDriverjdbc:oracle:thin:@localhost:1521:orcl or jdbc:oracle:thin:@//localhost:1521/XEPDB1
Microsoft SQL Servercom.microsoft.sqlserver.jdbc.SQLServerDriverjdbc:sqlserver://localhost:1433;databaseName=dbname;encrypt=false

Ensure the matching driver .jar is in JMETER_HOME/lib/ (ClassNotFound playbook).

3. Tune Connection Pool Sizing and Validation Query

Section titled “3. Tune Connection Pool Sizing and Validation Query”

In JDBC Connection Configuration:

  • Max Number of Connections: Set equal to or slightly higher than your active thread count (e.g. 50100).
  • Max Wait (ms): 10000 (10 seconds timeout before failing if pool is full).
  • Validation Query: Always set a lightweight ping query to discard broken sockets:
    • MySQL / PostgreSQL / MSSQL: SELECT 1
    • Oracle: SELECT 1 FROM DUAL
  • Test While Idle: True
  • Soft Min Evictable Idle Time: 60000

In JDBC Request:

  • If running SELECT queries, set Query Type to Select Statement.
  • If running INSERT, UPDATE, or DELETE, set Query Type to Update Statement.
  • In JDBC Connection Configuration, set Auto Commit to True for simple read queries, or False if managing multi-statement transactions.

To capture values returned by database queries:

  • Variable names: userId,userName,userEmail
  • In subsequent samplers, access individual rows: \${userId_1}, \${userId_2}, or count via \${userId_#}.
ResourceUse when
ClassNotFoundExceptionMissing JDBC driver JAR files in lib/
Database Test Plan guideStep-by-step user manual for JDBC testing
Functions and variablesPassing variables between JDBC and HTTP samplers

Should each thread have its own JDBC Connection Configuration?

Section titled “Should each thread have its own JDBC Connection Configuration?”

No. Place one JDBC Connection Configuration at the Thread Group or Test Plan root. All threads share the pooled connections efficiently.

Check the database server’s active locks and slow query log. Long-running queries hold connections checked out of the pool, starving other virtual users.

On this page