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()
The above code is correct. Just added the code below:
// instead of this
st.executeQuery(sql)// do something like
java.sql.ResultSet rs = st.executeQuery(query);and then iterate results as described here - https://docs.oracle.com/javase/tutorial/jdbc/basics/processingsqlstatements.html#processing_resultset_objects
while (rs.next()) {
String value = rs.getString("COLUMN_NAME");
log.info("COLUMN_NAME:"+value)
}