|
本帖最后由 zhenmaohui 于 2013-7-9 17:26 编辑
1、下载JDBC驱动(sqljdbc4.jar)
2、在run_time setting下的classpath把这驱动引入(选择java vuser协议)。
3.脚本如下:
import lrapi.lr;
import java.io.*;
import java.sql.*;
import lrapi.web;
public class Actions
{
int sum=0;
int ColumnCount=0;
//String dbserverip = lr.eval_string("<dbserver>");
//定义数据库连接串
String conURL="jdbc:sqlserver://LENOVO-SK1TUOP3;DatabaseName=MSSQL200512Q2EU";
//连接数据库用户名
String user="Astrob";
//数据库口令
String password="test";
Statement stat;
ResultSet Result1;
Connection conn;
public int init() throws Throwable {
//加载JDBC驱动
lr.think_time(5);
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("驱动加载完成");
//连接数据库
lr.think_time(5);
conn = DriverManager.getConnection(conURL,user,password);
lr.think_time(5);
stat=conn.createStatement();
return 0;
}//end of init
public int action() throws Throwable {
lr.think_time(5);
lr.start_transaction("lr_Query_data_trans");
//sql语句
Result1=stat.executeQuery("select * from ASTROB_RDF_ROAD_NAME");
ResultSetMetaData rsmd = Result1.getMetaData();
ColumnCount = rsmd.getColumnCount();
System.out.println("结果集的列数:" + ColumnCount);
if(ColumnCount==0)
{
lr.end_transaction("lr_Query_data_trans",lr.FAIL);
}
else
{
lr.end_transaction("lr_Query_data_trans",lr.PASS);
}
return 0;
}//end of action
public int end() throws Throwable {
Result1.close();
stat.close();
conn.close();
return 0;
}//end of end
} |
|