喜欢研究学习技术,喜欢和志同道合的人交流。
从事测试6年,专职性能3年经验,擅长性能测试,测试框架开发。
励志格言:只要想学习,永远都不会太晚;只要想进步,永远都会有空间。
LoadRunner之JAVA版测试mysql数据库
上一篇 /
下一篇 2018-06-20 10:43:41
/ 个人分类:性能测试
import
java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import lrapi.lr;
public class Actions
{
/**
* 注意JDK版本为1.6才可以
* classpath环境变量配置
*
*/
public static String url = "jdbc:mysql://localhost:3306/dangdang";
public static String userName = "root";
public static String passWord = "123456";
public static Connection conn;
public static Statement sta;
public static ResultSet res;
public static String
SQL = "select * from testtable";
public int init() throws Throwable {
Class.forName("com.mysql.jdbc.Driver");// 加载驱动程序
conn = DriverManager.getConnection(url, userName,passWord);// 连续
数据库
if (!conn.isClosed()){
System.out.println("连接数据库成功!");
}
sta = conn.createStatement();// statement用来执行SQL语句
return 0;
}
public int action() throws Throwable {
res = sta.executeQuery(SQL);// 执行SQL语句并返回结果集
while (res.next()) {
System.out.println(res.getString(1) + "\t" + res.getString(2) + "\t" + res.getString(3) + "\t" + res.getString(4));
}
return 0;
}
public int end() throws Throwable {
res.close();//关闭果集
sta.close();//关闭执行对象
conn.close();//数据库连接
return 0;
}
}
收藏
举报
TAG: