从Groovy [Soapui]运行以下数据库连接脚本时没有响应

时间:2016-11-13 03:20:45

标签: groovy soapui mariadb

我正在尝试从Groovy [soapUI]运行此脚本,但我没有收到错误,而且sql命令没有返回任何结果。我错过了这里至关重要的一切吗?

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()

此外,在添加一堆log.info语句后,我收到以下响应:

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

1 个答案:

答案 0 :(得分:0)

也许你应该对查询结果做些什么

y

然后按照here

所述迭代结果
// instead of this 
st.executeQuery(sql)

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