Application of JMeter Ssh+jdbc in BeanShell

Source: Internet
Author: User

Many friends have met the JMeter link database needs SSH to connect the server to connect the database, share the BeanShell ssh+jdbc usage.

ImportCom.jcraft.jsch.JSch; Importcom.jcraft.jsch.Session;ImportJava.sql.*; String User= "";//SSH connection user nameString password = "";//SSH Connection PasswordString host = "";//SSH ServerintPort =;//SSH Access PortTry{Jsch Jsch=NewJsch (); Session=jsch.getsession (user, host, port);  Session.setpassword (password); Session.setconfig ("Stricthostkeychecking", "no");  Session.connect (); System.out.println (Session.getserverversion ());//here to print the SSH server version informationintAssinged_port = Session.setportforwardingl (3376, "Mysqlip", Mysqlport);//3376 is the port that JDBC usesSystem.out.println ("localhost:" + assinged_port + "+" + Mysqlip + ":" +mysqlport); } Catch(Exception e) {e.printstacktrace ();  }; Connection Conn=NULL; ResultSet RS=NULL; Statement St=NULL; Try{class.forname ("Com.mysql.jdbc.Driver"); Conn= Drivermanager.getconnection ("Jdbc:mysql://127.0.0.1:3376/xhl_guild", "root", "12346");//here, write localhost or 127.0.0.1 .St =conn.createstatement (); String SQL= "Select User_id,u_nickname from base_user where user_id = 2;"; RS=st.executequery (SQL); while(Rs.next ()) {System.out.println (Rs.getint (1) + "\ T" +rs.getstring (2));} } Catch(Exception e) {e.printstacktrace (); }rs.close (); St.close (); Conn.close (); Session.disconnect ()

Application of JMeter Ssh+jdbc in BeanShell

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.