Connecting to MYSQL DB with the help of SSH tunnel

Hello Team,

I am new to Katalon and using katalon from few days. I have requirement where I need to connect to MySQL DB with the help of SSH tunnel. SSH tunnel uses .pem file for authentication.

I am using below two codes for creating SSH connection and connecting to MYSQL DB, Please find details below:

  1. Connect Over SSH


import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.sql.Connection;

public class MySqlConnOverSSH {
public static void main(String[] args) throws SQLException {

	int lport=5656;
    String rhost="";
    String host="";
    int rport=3306;
    String user="sshuser";
    String password="sshpassword";
    String dbuserName = "mysql";
    String dbpassword = "mysql123";
    String url = "jdbc:mysql://localhost:"+lport+"/mydb";
    String driverName="com.mysql.jdbc.Driver";
    Connection conn = null;
    Session session= null;
    	//Set StrictHostKeyChecking property to no to avoid UnknownHostKey issue
    	java.util.Properties config = new java.util.Properties(); 
    	config.put("StrictHostKeyChecking", "no");
    	JSch jsch = new JSch();
    	session=jsch.getSession(user, host, 22);
    	int assinged_port=session.setPortForwardingL(lport, rhost, rport);
        System.out.println("localhost:"+assinged_port+" -> "+rhost+":"+rport);
    	System.out.println("Port Forwarded");
    	//mysql database connectivity
        conn = DriverManager.getConnection (url, dbuserName, dbpassword);
        System.out.println ("Database connection established");
    }catch(Exception e){
    	if(conn != null && !conn.isClosed()){
    		System.out.println("Closing Database Connection");
    	if(session !=null && session.isConnected()){
    		System.out.println("Closing SSH Connection");


  1. Connect to mysql DB with the code provided at Katalon community :


def connectDB(String driverType ,String url, String dbname, String port, String username, String password){

	//Load driver class for your specific database type

	String conn = driverType + url + ":" + port + "/" + dbname


	//String connectionString = "jdbc:sqlite:" + dataFile

	if(connection != null && !connection.isClosed()){



What basically I need toperform below steps to connect to database:

  1. Connect to SSH tunnel using key authentication -> Available Java code


2.Connect to MySQL DB post successful SSH connection.


Need to perform all steps in Katalon, Any leads please help.

Can anyone help me over this?

Thanks for your help in advance :slight_smile: