(10) Jmeter operates database/INSERT data/reads CSV data/bean shell usage

1. Prepare the environment

Because Jmeter is written in Java, during the process of operating the database, you need to add the corresponding Jar package dependency according to the type of database.

  • Copy the database driver package tojmeter/lib

Insert image description here

2. Write jmeter script

  1. Add thread group
    Insert image description here
  2. Add the original configuration, JDBC Connection Configuration
    Insert image description here
    Insert image description here
  3. Add sampler, JDBC Request
    1. Set the statement to be executed

Insert image description here

  1. Perform new operations
    1. To add, delete or modify, select Update Statement
    2. Query, select Select Statement
    3. Stored procedure, select Callable Statement

Insert image description here

  1. Extension: read data from csv file, traverse and insert into database
    Insert image description here
  • Add configuration element
    Insert image description hereInsert image description here
  1. Encrypt a field before using csv data -> Use bean shell
    7. Add bean shell sampler

Insert image description here

Insert image description here

Insert image description here

  • Because there are 20 pieces of data in the csv, we need to set the product of the number of threads * the number of loops to 20
    Insert image description here

  • View Results
    Insert image description here

3. Parameterization

Insert image description here

  • Of course, you can also use functions and variables to replace
    Insert image description here

4. Save the select results as variables and use them as parameters for other requests.

Combined with foreach, serial requests

  1. Save query results in a variable
    Insert image description here
  2. Create logical controller, Foreach controller
    Insert image description here
  • View generated variables via debug sampler
    Insert image description here
  1. Create JDBC sampler under ForEach controller
    • Make the appropriate settings

Insert image description here

  • View the results tree viaView the results
    Insert image description here

Guess you like

Origin blog.csdn.net/futao__/article/details/127846384