loadrunner使用java vuser测试mysql性能
/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description:
*
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.sun.org.apache.xpath.internal.operations.String;
import lrapi.lr;
public class Actions
{
public int init() throws Throwable {
Class.forName("com.mysql.jdbc.Driver");// 加载驱动程序
String url = "jdbc:mysql://10.10.10.10:36001/message";// URL指向要访问的数据库名message_old
String user = "root";// MySQL配置时的用户名
String password = "############";// MySQL配置时的密码
Connection connection = DriverManager.getConnection(url, user,password);// 连续数据库
if (!connection.isClosed()){
System.out.println("Succeeded connecting to the Database!");
}
Statement statement = connection.createStatement();// statement用来执行SQL语句
System.out.println("initial_id" + "\t" + "user_id1"+ "\t" + "user_id2");
return 0;
}//end of init
public int action() throws Throwable {
String sql ="SELECT * from user WHERE user_id1=238 group by user_id1";
ResultSet rs = statement.executeQuery(sql);// 执行SQL语句并返回结果集
while (rs.next()) {
System.out.println(rs.getString("initi_id") + "\t"+ rs.getString("user_id1")+"\t"+rs.getString("user_id2"));
}
return 0;
}
public int end() throws Throwable {
rs.close();//关闭果集
connection.close();//数据库连接
return 0;
}//end of end
}
摘自 移动互联性能、android自动化、web自动化测试专栏
补充:综合编程 , 其他综合 ,