自动化测试中用到的一些功能类
作者:网络转载 发布时间:[ 2013/9/9 14:47:28 ] 推荐标签:
2、一些数据类型转换
public class Chanage {
//int to String
public static String IntToString(int i){
String s = Integer.toString(i);
return s;
}
//String to int
public static int StringToInt(String s){
int i = Integer.parseInt(s);
return i;
}
}
3、和数据库交互
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.mysql.jdbc.Connection;
class ConnMySQL {
Connection conn;
Statement stmt;
ResultSet rs1;
int rs2;
public void connection() throws Exception{
String db = "meeting";
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://172.16.3.9:3306/"+db;
String uname = "admin";
String pwd = "itserver";
//加载驱动
Class.forName(driver);
//连接数据库
conn = (Connection) DriverManager.getConnection(url, uname, pwd);
if(!conn.isClosed()){
//System.out.println("连接成功!");
}
}
//执行查询操作返回ResultSet类型
public void executeSql0(String sql) throws SQLException{
//创建语句对象,用来执行sql语句
stmt = conn.createStatement();
//执行sql
rs1 = stmt.executeQuery(sql);
while(rs1.next()){
String name = rs1.getString("meetingId");
String subject = rs1.getString("e164");
String regionName = rs1.getString("state");
System.out.println(name+" "+subject+" "+regionName);
}
rs1.close();
}
//执行查询操作返回ResultSet类型
public void executeSql1(String sql) throws SQLException{
//创建语句对象,用来执行sql语句
stmt = conn.createStatement();
//执行sql
rs1 = stmt.executeQuery(sql);
while(rs1.next()){
String id = rs1.getString("id");
String subject = rs1.getString("subject");
String startTime = rs1.getString("startTime");
String endTime = rs1.getString("endTime");
String organiger = rs1.getString("organiger");
String status = rs1.getString("status");
System.out.println(id+" "+subject+" "+startTime+" "+endTime+" "+organiger+" "+status);
}
rs1.close();
conn.close();
}
//执行增删改操作返回int类型
public void executeSql2(String sql) throws SQLException{
stmt = conn.createStatement();
rs2 = stmt.executeUpdate(sql);
stmt.close();
conn.close();
}
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11