LR介面測試---Java Vuser之jdbc調試前

來源:互聯網
上載者:User

標籤:

在eclipse下編寫好的代碼:

 1 import lrapi.lr; 2 import java.sql.Connection; 3 import java.sql.DriverManager; 4 import java.sql.PreparedStatement; 5 import java.sql.ResultSet; 6  7 public class Actions { 8 //定義使用者名稱,密碼,串連的URL 9 String username = "root";10 String password = "123456";11 String url = "jdbc:mysql://127.0.0.1:3306/oa";12 String sql = "select * from itcast_user where id = 2";13 public int init() throws Throwable {14 //1註冊mysql驅動15 Class.forName("com.mysql.jdbc.Driver");16 return 0;17 }// end of init18 19 public int action() throws Throwable {20 //2串連mysql,匯入java.sql.Connection21 Connection conn = DriverManager.getConnection(url,username,password);22 //3擷取sql執行器的類,匯入java.sql.preparedstatement23 PreparedStatement ps = conn.prepareStatement(sql);24 //4執行sql語句,擷取到執行結果對象ResultSet(匯入)25 ResultSet set = ps.executeQuery();26 //列印擷取到的資料27 while(set.next()){28 String name = set.getString("name");29 System.out.println("name"+name);30 }31 //關閉掉ResultSet,PreparedStatement,Connection32 set.close();33 ps.close();34 conn.close();35 return 0;36 }// end of action37 38 public int end() throws Throwable {39 40 return 0;41 }// end of end42 43 /*44 //程式去執行的入口,在LR中不用寫45 public static void main(String[] args) throws Throwable{46 Actions actions = new Actions();47 actions.init();48 actions.action();49 actions.end();50 }*/51 }

 

拷貝到LR並檢查是否有語法錯誤。

設定LR回合設定:Run-time Settings

一切準備就緒,接下來看是否查詢到資料,如所示有資料返回證明指令碼跑通:

 本文的指令碼只適用於調試用,因為還有需要最佳化的地方,比如添加參數化、事務、檢查點等。

LR介面測試---Java Vuser之jdbc調試前

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.