LR Interface Test---Java vuser for additional deletions

Source: Internet
Author: User
Tags throwable

1 import LRAPI.LR;2 3 import java.sql.Connection;4 import Java.sql.DriverManager;5 import java.sql.PreparedStatement;6 import Java.sql.ResultSet;7 8  Public classActions {9     //define the user name, password, URL of the connectionTenString username ="Root"; OneString Password ="123456"; AString URL ="JDBC:MYSQL://127.0.0.1:3306/HK"; -     //String sql = "SELECT * from teach where id =?"; -String sql ="Update teach set name =? WHERE id = 2"; theConnection conn =NULL; - PreparedStatement PS; -ResultSetSet=NULL; -     //all concurrent operations are performed only once and placed in the static code block +     Static{ -  +     //1 registering MySQL driver A         Try{ atClass.forName ("Com.mysql.jdbc.Driver"); -}Catch(ClassNotFoundException e) { - e.printstacktrace (); -         } -     } -      Public intinit () throws Throwable { in  -         //2 connecting MySQL, importing java.sql.Connection toconn =drivermanager.getconnection (Url,username,password); +         //3 Get the SQL Executor class, import java.sql.preparedstatement -PS =conn.preparestatement (SQL); the         return 0; *}//End of Init $ Panax Notoginseng      Public intaction () throws Throwable { -  the         //converting strings to shaping +         //integer.parseint ("<id>"); A         //in the SQL statement? Do the assignment, in order to do the parameterization the         //ps.setint (1, Integer.parseint ("<id>")); +Ps.setint (1,123456); -  $  $Lr.start_transaction ("Shiwu"); -  -  the         //4 Execute SQL statement, get to execution result object ResultSet (import) -         //set = Ps.executequery ();Wuyi  the         //if it's Insert,update,delete, -         introws =ps.executeupdate (); Wu          if(Rows >0 ){ -Lr.end_transaction ("Shiwu", LR. PASS); About}Else{ $Lr.end_transaction ("Shiwu", LR. FAIL); -          } -          -         //if (set.next () = = True) { A                      +           //lr.end_transaction ("Shiwu", LR. PASS); the  -         //}else{ $                      the           //lr.end_transaction ("Shiwu", LR. FAIL); the  the          // } the         //Print the acquired data - //While (Set.next ()) { in //int id = set.getint ("id"); the //System.out.println ("id" +id); the //        } About         return 0; the}//End of Action the  the      Public intEnd () throws Throwable { +         //turn off Resultset,preparedstatement,connection . -         //set.close ();//Update, delete, and insert do not use Set.close () to remove it the ps.close ();Bayi conn.close (); the         return 0; the}//End of End -      - /*//program to execute the entrance, in LR do not write the Public static void Main (string[] args) throws throwable{ the actions = new actions (); the actions.init (); the actions.action (); - actions.end (); the     } the */ the 94}

The above is the Java VUser additions and deletions of the script, which explicitly written to check and change the example.

Comments:

1, set run to see if there is Java classpath

2. Set up the JDBC package needed to run and add it in

3, attach a note, as shown:

LR Interface Test---Java vuser for additional deletions

Related Article

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.