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