Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 37 ยท Test Plans and Samplers

JDBC, TCP, FTP, SMTP and Other JMeter Samplers

Go beyond HTTP: test databases with the JDBC Request and connection configuration, plus TCP, FTP, SMTP, JMS and LDAP samplers, and the Debug and Test Action samplers.

HTTP is only one protocol among many. A shop depends on a database, a message queue, a mail server and a file transfer service, and any of them can become the bottleneck. JMeter ships with samplers for these protocols, so you can test a database directly or stress a queue without a web front end. This lesson tours the most useful ones and shows the JDBC sampler in detail, because database tests are the most common after HTTP.

Honesty note. JMeter cannot run here and there is no database server on this site. Everything JDBC-related is shown as configuration text. The runnable blocks are stand-ins: they run query-like code against in-memory JavaScript data so you can see how the sampler's result variables behave.

JDBC testing

Testing a database needs two elements: a JDBC Connection Configuration (the pool) and a JDBC Request (the query).

Step 1: add the driver

JMeter does not ship vendor JDBC drivers. Download the driver JAR for your database (PostgreSQL, MySQL/MariaDB, SQL Server, Oracle...), put it in lib/, and restart JMeter. Alternatively, point Test Plan > Add directory or jar to classpath at it. Use drivers from the vendor's official site.

Step 2: JDBC Connection Configuration

Add it as a config element (Add > Config Element > JDBC Connection Configuration):

Field Example
Variable Name for created pool shopDb (the link between config and requests)
Max Number of Connections 10 (match your thread count or pool plan)
Max Wait (ms) 10000
Validation Query SELECT 1
Database URL jdbc:postgresql://db.example.test:5432/shop_test
JDBC Driver class org.postgresql.Driver
Username / Password A test account: ${__P(dbUser,loadtest)}

Use a dedicated, test-only database user with the least privileges necessary, and never aim at production data.

Step 3: JDBC Request

Add Add > Sampler > JDBC Request and set Variable Name of Pool declared in JDBC Connection Configuration to the same name (shopDb). Then:

  • Query Type: Select Statement, Update Statement, Callable Statement, Prepared Select Statement, Prepared Update Statement, Commit, Rollback, AutoCommit(false) and so on.
  • Query: the SQL, without a trailing semicolon, one statement per sampler.
  • Parameter values / types for prepared statements: ${customerId},${status} and INTEGER,VARCHAR.
  • Variable names: comma-separated names to receive column values, for example id,total. For a result with several rows, JMeter creates id_1, id_2, ... and id_# with the row count.
  • Result variable name: stores the whole result as an object for use in scripts.

A typical use: read candidate ids to drive an API test. Prefer prepared statements with parameters over building SQL by string concatenation of variables: it is both safer and more realistic, since applications use prepared statements.

SQL
SELECT id, total FROM orders WHERE customer_id = ? AND status = ? LIMIT 5

(With parameter values ${customerId},${status} and types INTEGER,VARCHAR; the exact SQL dialect depends on your database.)

What JDBC tests tell you

They measure query time from the client, including network and pool wait. They are great for finding a slow query or testing a connection pool limit, but a direct JDBC load test skips the application layer, so use them to analyze the database, not to prove user-facing speed.

Stand-in: JDBC variables from a result

JS Stand-in: how JDBC variable names receive rows

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Other samplers

Sampler Used for Notes
TCP Sampler Raw TCP protocols Set server, port, text to send; choose TCPClient class, end-of-line byte, timeouts.
FTP Request File download/upload on FTP Needs host, remote file, local file; FTPS and SFTP need plugins.
SMTP Sampler Send test email Point at a test mail server (for example a local catch-all), never at real addresses.
Mail Reader Sampler Read via IMAP or POP3 For mailbox tests.
JMS Publisher / Subscriber / Point-to-Point Message queues Needs the broker's client JARs in lib/.
LDAP Request / Extended LDAP Directory services Authentication and lookups.
OS Process Sampler Run a command-line program Useful for setup scripts; keep commands safe.
Java Request Custom Java sampler classes For advanced users with their own code.
BeanShell / JSR223 Sampler Your own scripted sampler See JSR223 scripting.

JMeter's plugin ecosystem adds more (WebSocket, MQTT, gRPC, Kafka, SSH) through the Plugins Manager.

Debug Sampler and Test Action

Two small utility samplers deserve a place in every toolbox:

  • Debug Sampler produces no network traffic; its result shows the current JMeter variables, properties and system properties. Add it after a step and open the Results Tree to see what your extractors really produced. Disable it before load runs.
  • Test Action pauses (Pause in ms), stops a thread, or moves to the next loop, depending on settings. It is a controllable alternative to a timer: for example, Pause after the last request of an iteration, or Stop Thread when a condition is met.

Stand-in: a TCP echo exchange

TCP tests send text and read what comes back. The block below models an echo-style server with a one-line protocol and a TCP-sampler-like request.

JS Stand-in: a TCP sampler against a fake line protocol

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Practical advice for non-HTTP tests

  • Use a dedicated test instance of the database, queue or mail server.
  • Keep connection pool size comparable to what the real application uses, or you will measure pool contention that does not exist in production.
  • Add assertions, even simple ones: a Response Assertion on text such as OK, or a Duration Assertion.
  • For databases watch both sides: JMeter's timings and the database's own slow-query log and CPU.
  • Clean up rows created by write tests in a tearDown Thread Group.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where do you normally put a vendor's JDBC driver JAR for JMeter?

    JMeter loads driver classes from lib/ at startup, so restart after adding the JAR.
  2. 2. How do the JDBC Connection Configuration and JDBC Request know they belong together?

    The 'Variable Name for created pool' in the config must match the pool name in the request.
  3. 3. A JDBC Request with Variable names 'id' returns 3 rows. Which variables are created?

    JMeter appends _1, 2, ... for each row and sets name# to the number of rows.
  4. 4. What is the Debug Sampler for?

    It is a diagnostic sampler: add it, inspect the Results Tree, then disable it for load runs.

Summary

  • JDBC tests need a driver JAR in lib/, a JDBC Connection Configuration (pool) and a JDBC Request.
  • Result columns become name_1, name_2 ... plus name_# for the row count; prefer prepared statements.
  • TCP, FTP, SMTP, JMS, LDAP and OS Process samplers cover other protocols; plugins add more.
  • Debug Sampler reveals variables; Test Action controls pauses and stops.
  • Use test instances, least-privilege test accounts and clean up written data.

Next: JSR223 and Groovy Scripting