Forum Discussion

chiragverma123's avatar
chiragverma123
Contributor
9 years ago

Getting no response when I run the following database connection script from Groovy[Soapui]

I am trying to run this script from Groovy[soapUI] but i am not getting errors and not the sql command is not returning any results. am I missing anything crucial here?

 

 

import groovy.sql.Sql
import java.sql.*
import com.jcraft.jsch.JSch
import com.jcraft.jsch.Session


// ssh login
String sshHost = 'test.com'
String sshUser = 'test'
String sshPass = 'test'
int sshPort = 22

// database login
targetHost = 'localhost'
targetUser = 'test'
targetPass = 'test'
targetPort = 3306
lport = 4328

JSch jsch = new JSch();
Session session = jsch.getSession(sshUser, sshHost, sshPort);
session.setPassword(sshPass);
session.setConfig("StrictHostKeyChecking", "no");
System.out.println("Establishing Connection...");
session.connect();
int assinged_port=session.setPortForwardingL(lport, targetHost, targetPort);

Connection con = null;
String driver = "org.mariadb.jdbc.Driver";
String connectionString = "jdbc:mariadb://" + targetHost +":" + lport + "/";
con = DriverManager.getConnection(connectionString, targetUser, targetPass);
Statement st = con.createStatement();
String sql = "select * from SS_System.tblcompanies where companyid=495555"
st.executeQuery(sql);
st.close()
session.disconnect()