LoadRunner Java protocol to test SQL Performance

Source: Internet
Author: User

We may all know that the ODBC protocol can be recorded. SQL Server 2000 is the underlying protocol, so there are many things we don't want and there are many things, we don't know. so parameterization and maintenance scripts are too difficult .. for this reason, you must useJavaCode to write a testSQLProgram.

/** LoadRunnerJava SCR limit pt. (Build: 873) * Writer fangtiesui * SCR limit PT descr limit ption: SQL query Performance TestingScript * Date: 2008-09-19 */import Java. io. *; import lrapi. LR; import Java. SQL. *; public class actions {int sum = 0; Public int Init () throws throwable {return 0;} // end of init public int action () throws throwable {try {string sqldriver = "com. microsoft. JDBC. sqlserver. sqlserverdriver "; Class. forname (sqldriver); system. out. println (" DatabaseThe driver has been registered! "); String url =" JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = School "; string user =" sa "; string Password =" sa "; string sel = "select * from student where ID> 950"; connection conn = drivermanager. getconnection (URL, user, password); system. out. println ("database connection successful"); LR. start_transaction ("querying student table"); statement sta = Conn. createstatement (); resultset rs = sta.exe cutequery (SEL); system. out. print ("/t" + "ID" + "/t" + "name" + "/t" + "ADDR" + "/t" + "tel" + "/ N "); while (RS. next () {system. out. print ("/t" + Rs. getint (1); system. out. print ("/t" + Rs. getstring (2); system. out. print ("/t" + Rs. getstring (3); system. out. println ("/t" + Rs. getstring (4); sum = sum + 1;} Rs. close (); Sta. close (); Conn. close ();} catch (exception e) {e. printstacktrace (); system. out. println ("test failed");} LR. message ("sum =" + sum); LR. end_transaction ("querying student table", LR. auto); Return 0;} // end of actionpublic int end () throws throwable {return 0;} // end of end}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.