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{
Defines the database connection string
/*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 is a data source created from an Oracle database (after the Oracle database is installed, non-Oracle clients, starting-running the--oracle12--configuration and porting Tools--net Manager)
User name of the database
String user = "fasp_150001";
User Password for database
String Password = "1";
Load JDBC-ODBC Bridge Driver
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
Establish a connection to the data source specified by the URL
Connection conn = drivermanager.getconnection (dburl, user, password);
Use statement to query
Insert LoadRunner Transaction 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");
Each field name of the function output table
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 Transaction End
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
}
Scripting--loadrunner connecting Oracle database query data