LR的java协议压测PG库

/*
 * LoadRunner Java script. (Build: _build_number_)
 * 
 * Script Description: 
 *                     
 */
 
import lrapi.lr;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
 
public class Actions
{
    Connection conn = null;
 
    public int init() throws Throwable {
        try {
            Class.forName("org.postgresql.Driver");
            conn = DriverManager.getConnection("jdbc:postgresql://192.168.160.2:5432/csbsys","postgres","dragon123456");
            if (conn == null) {
  lr.abort();
     }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }catch (Exception e) {
            e.printStackTrace();
        }
 
 return 0;
    }//end of init
 
 
    public int action() throws Throwable {
        Statement st = conn.createStatement();
 ResultSet rs = null;
 
 // 场景SQL
 String exsql = "select reltuples from pg_class where relname = 'm_wb_swjl';";
        
// String exsql = "select * from m_wb_swjl where mid = '*****' and zjhm = '******';";//MID精确查询
 
 try {
     lr.start_transaction("多个条件精确查询");
     rs = st.executeQuery(exsql);
     if(rs!=null){
  lr.end_transaction("多个条件精确查询", lr.PASS);
     }else{
  lr.end_transaction("多个条件精确查询", lr.FAIL);
     }
     // 结果输出 while(rs.next()){ System.out.println(rs.getString(1));}
 }catch (Exception e) {
            e.printStackTrace();
        }
        rs.close();
        st.close();
        return 0;
    }//end of action
 
 
    public int end() throws Throwable {
        conn.close();
 return 0;
    }//end of end
}

 

posted on 2021-12-07 11:30  seamy  阅读(84)  评论(0编辑  收藏  举报