loadrunner 利用JDBC操作mysql数据库

import lrapi.lr;
import java.util.ArrayList;
import java.util.List;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class Actions

{
private List merchant=new ArrayList<String>();
private List org_id=new ArrayList<String>();
private List receipt_type=new ArrayList<String>();
private Connection conn=null;

private Statement stmt=null;

private ResultSet rs=null;
private String merchantid="";
private String server="";//数据库地址

private String dataBase="";//数据库名

private String username="";//用户名

private String passworkd="";//密码

public int init() throws Throwable{

Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://192.168.*.*:3320/ocean"; //mysql连接地址
String user = "coral";
String password = "pwd";
Class.forName ("com.mysql.jdbc.Driver");
conn = (Connection) DriverManager.getConnection ( url, user, password );

stmt=conn.createStatement();

return 0;

}

public int action() throws Throwable

{
merchantid=lr.eval_string("{IP}");
lr.start_transaction("aaaa");
rs=stmt.executeQuery("select t.product_name_id from t_coral_rakeback t where t.receipt_type='<receipt_type>' and t.org_id=<IP> and t.biz_type=<biz>");

while(rs.next()&& !"".equals(rs.getString("product_name_id")))

{
lr.error_message("org"+lr.eval_string("<IP>"));
lr.error_message("product_name_id"+rs.getString("product_name_id")); //打印出查询的结果
//lr.error_message("receipt_type"+rs.getString("receipt_type"));
merchant.add(merchantid); //
org_id.add(lr.eval_string("<IP>"));
receipt_type.add(rs.getString("product_name_id"));

}
lr.end_transaction("aaaa", lr.PASS);
return 0;

}

public int end() throws Throwable{
System.out.println("end=====merchant=============");
for (Object object : merchant) {
lr.error_message((String)object);
}
lr.error_message("org_id============");
for (Object object1 : org_id) {
lr.error_message((String)object1);
}
lr.error_message("product_name_id============");
for (Object object2 : receipt_type) {
lr.error_message((String)object2);
}
stmt.close();

conn.close();

return 0;

}

}

上一篇:梯段下降算法


下一篇:思维题 UVA 10881 Piotr's Ants