Home > Database > Mysql Tutorial > loadrunner连接数据库sqlserver2008(2005)

loadrunner连接数据库sqlserver2008(2005)

WBOY
Release: 2016-06-07 15:45:33
Original
1407 people have browsed it

近期通过数据库压力测试,看了一些资料,方法都差不多。 1、下载JDBC驱动(sqljdbc4.jar) 2、在run_time setting下的classpath把这驱动引入。 3、编写及哦啊本 /* * LoadRunner Java script. (Build: _build_number_) * * Script Description: * */ import

近期通过数据库压力测试,看了一些资料,方法都差不多。

1、下载JDBC驱动(sqljdbc4.jar)

2、在run_time setting下的classpath把这驱动引入。

3、编写及哦啊本

/*
 * LoadRunner Java script. (Build: _build_number_)
 * 
 * Script Description: 
 *                     
 */

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("");
 //定义数据库连接串
 String conURL="jdbc:sqlserver://xx.xx.x.xx\\sql1;DatabaseName=NewDB";
 //连接数据库用户名
 String user="prj_tmp_rw";
 //数据库口令
 String password="xxxxx";
 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");
                Result1=stat.executeQuery("");
                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
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template