Learn how to use the JSR223 sampler to store SQL query results into a database table
P粉633309801
P粉633309801 2023-08-29 22:13:53
0
1
414

Please provide step-by-step process

How to use jsr223 sampler to connect to MySQL database and execute queries, and store the results in the database table? Please provide sample code for this theme

P粉633309801
P粉633309801

reply all (1)
P粉302484366
  1. DownloadMySQL JDBC Driverand put it into the "lib" folder under the JMeter installation directory (or put it into other files in theJMeter classpathfolder)

  2. Restart JMeter to load the .jar file

  3. AddThread Groupto your test plan

  4. AddJSR223 Samplerto your thread group

  5. Put the following code into the "Script" area:

    import groovy.sql.Sql def url = 'jdbc:mysql://your-database-host:your-database-port/your-database-name' def user = 'your-username' def password = 'your-password' def driver = 'com.mysql.cj.jdbc.Driver' def sql = Sql.newInstance(url, user, password, driver) def query= 'INSERT INTO your-table-name (your-first-column, your-second-column) VALUES (?,?)' def params = ['your-first-value', 'your-second-value'] sql.executeInsert query, params sql.close()
  6. Changeyour-database-host,your-database-port, etc. to the real IP address, port, credentials, table name, column name, etc.

  7. Enjoy it

More information:


Side note: I believe it would be faster and easier to use theJDBC Requestssampler

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!