一、代接脚本代码,选择oracle协议,配置数据源,配置成功后,脚本代码如下
/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description:
*
*/
import java.io.*;
import java.sql.*;
import lrapi.lr;
public class Actions
{
int sum=0;
public int init() throws Throwable {
return 0;
}
public int action() throws Throwable {
//String opter="'79408'";
//int opters =Integer.parseInt("'79408'");
try{
//定义了数据库连接串
String dbUrl = "jdbc:odbc:Cushou";
//数据库的用户名
String user = "amque";
//数据库的用户口令
String password = "amque*&)876";
//加载jdbc-odbc bridge驱动程序
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//与url指定的数据源建立连接
Connection conn = DriverManager.getConnection(dbUrl, user, password);
//采用Statement进行查询
//插入LoadRunner的事务lr_select_data_trans
lr.start_transaction("search");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT ci.id, ci.customer_code, ci.name, ci.collection_date, ci.overdue_count, Sum(oi.overdue_principal), Max(oi.overdue_period), sc_1.content_lang1, si.segment_name, tcu.unit_name, tcs.set_name, ci.priority, ciop.op_content, ciop.op_code, CASE WHEN is_processed.processedcnt > 0 THEN 'Y' ELSE 'N' END, cbin.cbdate, cbin.opdate, pbbi.pbdate, pbbi.pbamount, active.collection_activitive FROM t_customer ci LEFT JOIN t_overdue_info oi ON ci.id = oi.customer_id AND oi.overdue_status = 'Y' LEFT JOIN (SELECT pbi.cust_id,pbi.payback_date pbdate, pbi.payback_amount pbamount FROM t_payback_info pbi WHERE pbi.id IN (SELECT Max(id) FROM t_payback_info GROUP BY cust_id)) pbbi ON ci.id = pbbi.cust_id LEFT JOIN (SELECT tol.cust_id, Max(tcbi.call_back_date) cbdate, Max(tol.operation_date) opdate FROM t_operation_log tol LEFT JOIN t_call_back_info tcbi ON tol.call_back_info_id = tcbi.id GROUP BY tol.cust_id) cbin ON ci.id = cbin.cust_id LEFT JOIN (SELECT cie.cust_id,tops.code op_code, tops.content_lang1 op_content,cie.operation_status FROM t_customer_info_ext cie, t_sys_code tops WHERE cie.operation_status = tops.id) ciop ON ci.id = ciop.cust_id LEFT JOIN t_sys_code sc_1 ON ci.operation_result_id = sc_1.id LEFT JOIN (SELECT tolg.collection_activitive,tolg.cust_id FROM t_operation_log tolg,(SELECT Max(operation_date) AS maxdate, cust_id FROM t_operation_log GROUP BY cust_id) tmp WHERE tolg.cust_id = tmp.cust_id AND tolg.operation_date = tmp.maxdate) active ON ci.id = active.cust_id LEFT JOIN (SELECT ct.cust_id, Count(* ) processedcnt FROM t_collection_task ct, t_sys_code sc WHERE ct.task_opt_status = sc.id AND ct.operator = '<operator>' AND sc.code = '03' AND ct.queue_id IS NULL GROUP BY ct.cust_id) is_processed ON is_processed.cust_id = ci.id,t_segment_info si,t_segment_tree st,t_collection_unit tcu, t_collection_set tcs WHERE ci.segment_id = si.id AND ci.is_need_review = 'N' AND st.id = si.tree_id AND st.create_unit_id = tcu.id AND ci.collection_set_id = tcs.id AND ci.id IN (SELECT DISTINCT cc.cust_id FROM t_collection_case cc, t_collection_task ct, t_sys_code sc_2 WHERE cc.id = ct.case_id AND cc.is_complete = 'N' AND ct.task_opt_status = sc_2.id AND ((sc_2.code = '03' AND ct.operator = '<operator>' AND ct.queue_id IS NULL ) OR (sc_2.code = '02' AND ct.operator = '<operator>' AND ct.queue_id IS NULL ) OR (sc_2.code = '01' AND ct.operator = '<operator>' AND ct.queue_id IS NULL ))) GROUP BY ci.id,ci.customer_code, ci.name,ci.collection_date, ci.overdue_count,sc_1.content_lang1, si.segment_name, tcu.unit_name, tcs.set_name, ci.priority, ciop.op_code, ciop.op_content,is_processed.processedcnt, cbin.cbdate, cbin.opdate, pbbi.pbdate, pbbi.pbamount, active.collection_activitive ORDER BY cbin.cbdate DESC, ci.customer_code ASC, ci.id ASC");
//ResultSet rs = stat.executeQuery("SELECT ci.id, ci.customer_code, ci.name, ci.collection_date, ci.overdue_count, Sum(oi.overdue_principal), Max(oi.overdue_period), sc_1.content_lang1, si.segment_name, tcu.unit_name, tcs.set_name, ci.priority, ciop.op_content, ciop.op_code, CASE WHEN is_processed.processedcnt > 0 THEN 'Y' ELSE 'N' END, cbin.cbdate, cbin.opdate, pbbi.pbdate, pbbi.pbamount, active.collection_activitive FROM t_customer ci LEFT JOIN t_overdue_info oi ON ci.id = oi.customer_id AND oi.overdue_status = 'Y' LEFT JOIN (SELECT pbi.cust_id,pbi.payback_date pbdate, pbi.payback_amount pbamount FROM t_payback_info pbi WHERE pbi.id IN (SELECT Max(id) FROM t_payback_info GROUP BY cust_id)) pbbi ON ci.id = pbbi.cust_id LEFT JOIN (SELECT tol.cust_id, Max(tcbi.call_back_date) cbdate, Max(tol.operation_date) opdate FROM t_operation_log tol LEFT JOIN t_call_back_info tcbi ON tol.call_back_info_id = tcbi.id GROUP BY tol.cust_id) cbin ON ci.id = cbin.cust_id LEFT JOIN (SELECT cie.cust_id,tops.code op_code, tops.content_lang1 op_content,cie.operation_status FROM t_customer_info_ext cie, t_sys_code tops WHERE cie.operation_status = tops.id) ciop ON ci.id = ciop.cust_id LEFT JOIN t_sys_code sc_1 ON ci.operation_result_id = sc_1.id LEFT JOIN (SELECT tolg.collection_activitive,tolg.cust_id FROM t_operation_log tolg,(SELECT Max(operation_date) AS maxdate, cust_id FROM t_operation_log GROUP BY cust_id) tmp WHERE tolg.cust_id = tmp.cust_id AND tolg.operation_date = tmp.maxdate) active ON ci.id = active.cust_id LEFT JOIN (SELECT ct.cust_id, Count(* ) processedcnt FROM t_collection_task ct, t_sys_code sc WHERE ct.task_opt_status = sc.id AND ct.operator = '79408' AND sc.code = '03' AND ct.queue_id IS NULL GROUP BY ct.cust_id) is_processed ON is_processed.cust_id = ci.id,t_segment_info si,t_segment_tree st,t_collection_unit tcu, t_collection_set tcs WHERE ci.segment_id = si.id AND ci.is_need_review = 'N' AND st.id = si.tree_id AND st.create_unit_id = tcu.id AND ci.collection_set_id = tcs.id AND ci.id IN (SELECT DISTINCT cc.cust_id FROM t_collection_case cc, t_collection_task ct, t_sys_code sc_2 WHERE cc.id = ct.case_id AND cc.is_complete = 'N' AND ct.task_opt_status = sc_2.id AND ((sc_2.code = '03' AND ct.operator = '79408' AND ct.queue_id IS NULL ) OR (sc_2.code = '02' AND ct.operator = '79408' AND ct.queue_id IS NULL ) OR (sc_2.code = '01' AND ct.operator = '79408' AND ct.queue_id IS NULL ))) GROUP BY ci.id,ci.customer_code, ci.name,ci.collection_date, ci.overdue_count,sc_1.content_lang1, si.segment_name, tcu.unit_name, tcs.set_name, ci.priority, ciop.op_code, ciop.op_content,is_processed.processedcnt, cbin.cbdate, cbin.opdate, pbbi.pbdate, pbbi.pbamount, active.collection_activitive ORDER BY cbin.cbdate DESC, ci.customer_code ASC, ci.id ASC");
lr.start_transaction("outcontent");
lr.message("\t"+"ci.id"+"\t"+"ci.customer_code"+"\t"+"ci.name"+"\n");
//函数输出表的各个字段名字
while(rs.next())
{
lr.message("\t"+rs.getString(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\n");
sum=sum+1;
}
lr.end_transaction("outcontent",lr.AUTO);
rs.close();
stat.close();
conn.close();
//lr.message("Sum="+sum);
// lr_select_data_trans事务结束
lr.end_transaction("search",lr.AUTO);
}catch(Exception e){
e.printStackTrace();
System.out.println("Test Failed");
}
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}