loadruner中加中Java_Script

需要加載jdk1.6


/*

 * LoadRunner Java script. (Build: _build_number_)

 * 

 * Script Description: 

 *                     

 */


import lrapi.lr;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;


public class Actions

{


public int init() throws Throwable {

return 0;

}//end of init



public int action() throws Throwable {

            String url = "jdbc:mysql://localhost:3306/school?useUnicode=true&characterEncoding=UTF-8";

String username = "root";

String password = "";


Connection conn = null;

PreparedStatement stmt = null;

ResultSet rs = null;

int idhao;


try {

Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection(url, username, password);

// String sql =

// "insert into Students values (8,'admin',12,'m','[email protected]','abc');";

String sql = "insert into Students values (?,?,?,?,?,?);";

stmt = conn.prepareStatement(sql);

//注意:下標從1開始。


stmt.setInt(1, 2);  //?整數暫時不知道怎麼參數

stmt.setString(2, "<name>");  //參數

stmt.setInt(3, 24);  //沒有參數成功

stmt.setString(4, "<sex>"); //參數

stmt.setString(5, "<email>"); //參數

stmt.setString(6, "<address>"); //參數

            int result = stmt.executeUpdate();

            if(result>0)

            {

            System.out.println("插入成功!");

            }

            else

            {

            System.out.println("插入失敗!");

            }

            

} catch (Exception ex) {

ex.printStackTrace();

} finally {


try {

stmt.close();

conn.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}


return 0;

}//end of action



public int end() throws Throwable {

return 0;

}//end of end

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章