public static void main(String[] args) {
String filename ="test.csv";
try {
FileWriter fw = new FileWriter(filename);
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:sqlserver://server;databaseName;","user","password");
String query = "select * from table";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
fw.append(rs.getString(1));
fw.append(',');
fw.append(rs.getString(2));
fw.append(',');
fw.append(rs.getString(3));
fw.append('\n');
}
fw.flush();
fw.close();
conn.close();
System.out.println("CSV File is created successfully.");
} catch (Exception e) {
e.printStackTrace();
}
}
我只想使用BeanShell Sample或JSR223 Timer在jmeter中执行这个java文件。有人可以帮忙吗?
答案 0 :(得分:1)
你不需要一个档案。
在您的JSR223 Timer中,选择Groovy作为语言,并将代码放入其中,而不使用主函数签名:
的System.out.println("你好&#34);
确保选中“缓存...”