Forum Discussion

chiragverma123's avatar
chiragverma123
Contributor
8 years ago

Trying to connect to Database to check values were updated.

I am trying to connect to the database using SOAPUI to check if the values were updated properly. But I am having trouble doing it. Also, due to the security reasons I will need to login through SSH and we are currently using maria db(not sure which driver i use matters here)

 

Here is what I tried but no luck

 

 

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


// ssh login
def sshHost = ''
def sshUser = ''
def sshPass = ''
def sshPort = 22

// database login
def targetHost = '127.0.0.1'
def targetUser = ''
def targetPass = ''
def targetPort = '3306'

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(0, targetHost, targetPort);

Connection con = null;
def driver = 'org.mariadb.jdbc.Driver'
def connectionString = 'jdbc:mariadb://localhost:3306/db'con = DriverManager.getConnection(connectionString, targetUser, targetPass);
Statement st = con.createStatement();
String sql = "select * company "st.execute(sql);