P粉3024843662023-08-30 20:29:00
DownloadMySQL JDBC Driver and put it into the "lib" folder under the JMeter installation directory (or put it into other files in the JMeter classpath folder)
Restart JMeter to load the .jar file
Add Thread Group to your test plan
Add JSR223 Sampler to your thread group
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()
Change your-database-host
, your-database-port
, etc. to the real IP address, port, credentials, table name, column name, etc.
Enjoy it
More information:
Side note: I believe it would be faster and easier to use the JDBC Requests sampler