Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Java code to open SSH tunnel connection?

Hi, does anyone here have a recommended method to using java code to open a remote ssh tunnel connection to start out a job?
To at least start somewhere I downloaded and added the latest version of jsch jsch-0.1.50.jar to my user libraries
Also found a sample script to connect here: http://mws-mdm.blogspot.ca/2013/07/jdbc-over-ssh-tunnel.html
To get myself started I put that script verbatim into a tJava component; but it looks like the script is going to need to be Talend-ized in order to make it work. Tried it out of the box and got a number of errors:
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
Syntax error on token "import", assert expected
java.sql.Connection cannot be resolved to a variable
Syntax error on token "import", assert expected
java.sql.DriverManager cannot be resolved to a variable
Syntax error on token "import", assert expected
java.util.Properties cannot be resolved to a variable
Syntax error on token "import", assert expected
com.jcraft cannot be resolved to a variable
Syntax error on token "import", assert expected
com.jcraft cannot be resolved to a variable
Syntax error on token "import", assert expected
com.jcraft cannot be resolved to a variable
Illegal modifier for the local class CTestDriver; only abstract or final is permitted
The method doSshTunnel cannot be declared static; static methods can only be declared in a static or top level type
JSchException cannot be resolved to a type
JSch cannot be resolved to a type
JSch cannot be resolved to a type
Session cannot be resolved to a type
Properties cannot be resolved to a type
Properties cannot be resolved to a type
The method main cannot be declared static; static methods can only be declared in a static or top level type
The method doSshTunnel(String, String, String, int, String, int, int) from the type CTestDriver refers to the missing type JSchException
Connection cannot be resolved to a type
DriverManager cannot be resolved
at natcobidw.testingssh_0_1.TestingSSH.tJava_1Process(TestingSSH.java:341)
at natcobidw.testingssh_0_1.TestingSSH.runJobInTOS(TestingSSH.java:1308)
at natcobidw.testingssh_0_1.TestingSSH.main(TestingSSH.java:1173)

Perhaps someone could help me tweak my method to get it working?
Or, perhaps someone has already gone down this path and could lay out some steps for me to follow?
Thank You 0683p000009MACn.png
PS - I'm attempting to connect to a remote MySQL database
Labels (5)
10 Replies
cacak
Contributor
Contributor

There is a user component in Talend Exchange called tSshTunnel. I would try this.

How to configure tSSHTunnel or tSSH to connect MySql with SSH?
I have a problem to connect to MySql with SSH, i dont know about the command on tSSH or tSystem
Hope somebody can help me.