清单 1. 将记录插入数据库
package com.ibm.jmetertest; import java.sql.*; public class JMeterPopulator { public static void main(String[] args) { try { Class.forName("COM.ibm.db2.jdbc.app.DB2Driver"); String dbName = "loaddb"; String url = "jdbc:db2:" + dbName; String userName = "db2admin"; String password = "db2admin"; Connection con = DriverManager.getConnection(url,userName, password); int numOfTestRecords = 30000; PreparedStatement statement = con.prepareStatement("INSERT INTO LOADTABLE VALUES(?,?,?)"); for (int i =0; i<numOfTestRecords; i++) { statement.setString(1,"Col1Test-" + i); statement.setString(2,"Col2Test-" + i); statement.setString(3,"Col3Test-" + i); statement.executeUpdate(); System.out.println(i); } } catch(Exception e) { System.out.println("An error has occurred: " + e.toString()); e.printStackTrace(); } } } |
现在我们有了相当数量的记录,让我们用 JMeter 来测试一下查询性能。
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/