Loadrunner 11 uses Java protocol to operate oracle Database

Keywords: JDK Java Oracle SQL

Tool preparation

​JDK

Since it is a Java protocol, JDK is essential, but the largest version of JDK supported by lr11 is only jdk1.6, and it must be 32 bits. ​

jdbc connects jar packages

To connect to oracle database, you need to prepare the database-driven jar package and select the corresponding version of the jar package according to the version of oracle


Script creation

Start Vugen

Open load runner 11, virtual user.


Protocol selection

File - > New - > selection protocol: "Java Vuser" - > create


Script writing






Code segment

import java.io.*;
import java.sql.*;
import lrapi.lr;

public class Actions
{
    
    String dbUrl = "jdbc:oracle:thin:@10.1.30.6:1521:cfs";

    String user = "BZCW";

    String password = "123456a?";

    Connection conn= null;

    Statement stat = null;

    /*Receive the result set returned by the select operation, if it is an add-delete operation, it is not necessary.*/
    ResultSet rs = null;

	public int init() throws Throwable {

        Class.forName("oracle.jdbc.OracleDriver").newInstance();

        conn = DriverManager.getConnection(dbUrl, user, password);

	stat = conn.createStatement();
		return 0;

	}//end of init

	public int action() throws Throwable {

   try{

       /*SQL statement for insertion operation*/
       String str="INSERT INTO APP_USER_INFO (ID,USER_ID,USER_NAME,USER_PHONE,USER_IDCARD,USER_PASSWORD,USER_STAUS,RSET_PWD_M,USE_PWD_M,ERR_LOGIN_COUNT,LAST_LOGIN_DATE,CREATE_USER,CREATE_DATE,UPDATE_USER,UPDATE_DATE,REMARK,RES_INFO,SESSION_ID,FIRST_LGN_DATE,AES_PASSWORD,ENP_ID,ENP_NAME,USE_PWD_S,FINGERPRINT_PWD) values ('<ID>','','zhangsan<USER_NAME>','188<USER_PHONE>','<USER_IDCARD_1><USER_IDCADR>','DC483E80A7A0BD9EF71D8CF973673924','0','1','1',0,to_date ('2007-11-15','YYYY-MM-DD'),'',to_date ('2007-11-15','YYYY-MM-DD'),'',to_date ('2007-11-15','YYYY-MM-DD'),'','remarkMessage','0370e72c-1fe5-4ec1-a160-a3adf4e64e66','','gU15Wr5rOg7p72vpXACDIw==','0,22101003020','A certain limited liability company','0','')";
       //Note that there is no need to add after the SQL statement.
       //String str="SELECT * FROM APP_USER_INFO";

       lr.start_transaction("insert_into_userinfo");

       /*If the operation type is select, using the excuteQuery method, the query operation returns to the recordset, which needs to be received by rs object.*/
       //rs = stat.executeQuery(str);

       /*If the operation type is update, insert, delete, and the executeUpdate method is used, the number of items affected (int) is returned, and if the creat table or drop table is returned with a value of 0.*/
       stat.executeUpdate(str);
               
       lr.end_transaction("insert_into_userinfo",lr.AUTO);
	
        }catch(Exception e){

                e.printStackTrace();

               System.out.println("Test Failed");

         }
	     
		return 0;
	}//end of action

        public int end() throws Throwable {

	    stat.close();

	    conn.close();

	    rs.close();

        return 0;

    }//end 0f end
}


Note:

1. dbUrl, user, password, conn, stat, rs are defined as global variables outside the action method because when loadrunner is concurrent, the action method will be executed repeatedly. If placed in the action, the connection will be created repeatedly to occupy database resources, which has an impact on the test results.

2. Introducing the resultset set set set class is to store the result set for the query class transaction.

3. There is no need to add ";" when the required SQL statements are stored as strings.

4. Use the executeQuery(stirng) function if it is a query operation, and the executeUpdate(str) function if it is an addition or deletion.


Environment settings

JDK settings

F4->classpath

1. Introducing ojdbc's jar package 2. Introducing the lib Library of jdk

JDK path

F4 - > Java Vm - > user specified JDK - > Installation path of input jdk, such as: I: Program Files (x86) Java jdk1.6.0_39


Copy the jdk address to the later value

Script Compilation

At the end of the setup, click OK to save, compile and prompt: No errors detected, indicating that the compilation passed.


Parametric processing

Sequential Incremental Parameters

Because some data need to be numbered for inserting data records, such as fields like ID, when setting parameters, choose the parameterized type: UniqueNumber.

Stochastic parameters

This kind of data is because the business system requires different data between each data, such as the user's mobile phone number, identity card fields. When setting parameterization, choose Random Number as the parameterization type.


Note: If the field length is insufficient when parameterized, it can be parameterized by splicing, that is, a field can be composed of multiple parameterized data. The largest number supported by Random Number is 4294967295.


Setting up iterations, startup scripts


How much data are produced?

F4->pacing->number of Iterations:1000​



Successful implementation

Posted by The voice on Thu, 23 May 2019 12:57:41 -0700