標籤:效能測試
import java.io.*;
import java.sql.*;
import lrapi.lr;
public class Actions
{
int sum=0;
public int init() throws Throwable {
return 0;
}//end of init
public int action() throws Throwable {
try{
//定義了資料庫連接串
/*DSN=ORACL_LR;UID=FASP_150001;PWD=1;DBQ=192.168.100.218:1521/ORCL;
DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;
BNF=F;BAM=IfAllSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=F;CSR=F;FWC=F;
FBS=64000;TLO=O;MLD=0;ODA=F;*/
String dbUrl = "jdbc:odbc:ORACL_LR"; //ORACL_LR是通過oracle資料庫建立出來的資料來源(安裝完oracle資料庫後,非oracle用戶端,在開始--運行--oracle12--配置和移植工具--net manager)
//資料庫的使用者名稱
String user = "FASP_150001";
//資料庫的使用者口令
String password = "1";
//載入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("lr_select_data_trans");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT code FROM fasp_t_causer where rownum<10;");
lr.message("\t"+"code"+"\n");
//函數輸出表的各個欄位名字
while(rs.next())
{
lr.message("\t"+rs.getString(1)
+"\n");
sum=sum+1;
}
rs.close();
stat.close();
conn.close();
lr.message("Sum="+sum);
// lr_select_data_trans事務結束
lr.end_transaction("lr_select_data_trans ",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
}
指令碼——loadrunner串連oracle資料庫查詢資料