protea protea - 1 year ago 81
Groovy Question

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 = ''
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.setConfig("StrictHostKeyChecking", "no");
System.out.println("Establishing Connection...");
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"

Also, after adding bunch of statements I am getting the following response:

Sun Nov 13 21:39:30 EST 2016:INFO:com.jcraft.jsch.Session@4e6b3063
Sun Nov 13 21:39:31 EST 2016:INFO:null
Sun Nov 13 21:39:31 EST 2016:INFO:4336
Sun Nov 13 21:39:31 EST 2016:INFO:jdbc:mysql://localhost:4336/
Sun Nov 13 21:39:31 EST 2016:INFO:org.mariadb.jdbc.MariaDbConnection@14f67389
Sun Nov 13 21:39:31 EST 2016:INFO:org.mariadb.jdbc.MariaDbStatement@401b321f
Sun Nov 13 21:39:31 EST 2016:INFO:org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet@74b9f5af

Answer Source

Perhaps you should do something with the query result

// instead of this 

// do something like
java.sql.ResultSet rs = st.executeQuery(query);

and then iterate results as described here

while ( {
    String value = rs.getString("COLUMN_NAME");"COLUMN_NAME:"+value)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download