使用java代码创建jdbc的Jmeter测试

使用java代码创建jdbc的Jmeter测试,java,jdbc,jmeter,Java,Jdbc,Jmeter,我想使用java代码创建JDBC的JMeter测试。我尝试了以下代码。对我来说,状态为200很好,但是这些值没有存储在MySQL数据库中。任何人都可以帮助我找到这段代码中的错误,或者提供一些适当的解决方案 public class Jdbc_Sampler { public static void main(String[] argv) throws Exception { final String jmeterHome = "C:\\apache-jmeter-

我想使用java代码创建JDBC的JMeter测试。我尝试了以下代码。对我来说,状态为200很好,但是这些值没有存储在MySQL数据库中。任何人都可以帮助我找到这段代码中的错误,或者提供一些适当的解决方案

 public class Jdbc_Sampler {

public static void main(String[] argv) throws Exception {
    
    final String jmeterHome = "C:\\apache-jmeter-5.3";

    StandardJMeterEngine jmeter = new StandardJMeterEngine();
    JMeterUtils.setJMeterHome(jmeterHome);
    JMeterUtils.loadJMeterProperties(jmeterHome + System.getProperty("file.separator") + "bin" + System.getProperty("file.separator") + "jmeter.properties");

    HashTree testPlanTree = new HashTree();

    DataSourceElement jdbcDataSource = new DataSourceElement();
    jdbcDataSource.setName("JDBC Connection Configuration");
    jdbcDataSource.setProperty("dataSource", "variable_name");
    jdbcDataSource.setProperty("dbUrl", "jdbc:mysql://localhost:3306/mysqldb?useSSL=false");
    jdbcDataSource.setProperty("driver", "com.mysql.cj.jdbc.Driver");
    jdbcDataSource.setProperty("username", "root");
    jdbcDataSource.setProperty("password", "root");
    jdbcDataSource.setProperty("poolMax", "0");
    jdbcDataSource.setProperty("connectionAge", "5000");
    jdbcDataSource.setProperty("timeout", "10000");
    jdbcDataSource.setProperty("trimInterval", "60000");
    jdbcDataSource.setProperty(TestElement.TEST_CLASS, DataSourceElement.class.getName());
    jdbcDataSource.setProperty(TestElement.GUI_CLASS, TestBeanGUI.class.getName());

    JDBCSampler jdbcSampler = new JDBCSampler();
    jdbcSampler.setName("JDBC Request");
    jdbcSampler.setProperty("dataSource", "variable_name");
    jdbcSampler.setProperty("queryType", "Update Statement");
    jdbcSampler.setProperty("query", "Insert into tablenm values(7,'ghi',10);");
    jdbcSampler.setProperty(TestElement.TEST_CLASS, JDBCSampler.class.getName());
    jdbcSampler.setProperty(TestElement.GUI_CLASS, TestBeanGUI.class.getName());

    LoopController loopController = new LoopController();
    loopController.setLoops(1);
    loopController.setFirst(true);
    loopController.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());
    loopController.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName());
    loopController.initialize();

    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setName("Example Thread Group");
    threadGroup.setNumThreads(1);
    threadGroup.setRampUp(1);
    threadGroup.setSamplerController(loopController);
    threadGroup.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());
    threadGroup.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName());

    TestPlan testPlan = new TestPlan("JMeter JDBC Test Plan");
    testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());
    testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());
    testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());

    testPlanTree.add(testPlan);
    HashTree threadGroupHashTree = testPlanTree.add(testPlan, threadGroup);
    threadGroupHashTree.add(jdbcDataSource);
    threadGroupHashTree.add(jdbcSampler);

    SaveService.saveTree(testPlanTree, new FileOutputStream(jmeterHome + System.getProperty("file.separator") + "jdbc.jmx"));


    Summariser summer = null;
    String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");
    if (summariserName.length() > 0) {
        summer = new Summariser(summariserName);
    }

    String logFile = jmeterHome + System.getProperty("file.separator") + "jdbc.jtl";
    ResultCollector logger = new ResultCollector(summer);
    logger.setFilename(logFile);
    testPlanTree.add(testPlanTree.getArray()[0], logger);

    jmeter.configure(testPlanTree);
    jmeter.run();

    System.exit(0);


  }
 }

提交/关闭jdbc连接?我也尝试过,但没有帮助。