You are not logged in.

Unanswered posts



Important! This site has been replaced. All content here is read-only. Please visit our brand-new community at https://community.talend.com/. We look forward to hearing from you there!



#1 2014-02-13 18:59:49

ddctf
Member
213 posts

ddctf said:

Java code to open SSH tunnel connection?

Tags: [java, mysql, ssh]

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 … unnel.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 smile

PS - I'm attempting to connect to a remote MySQL database

Last edited by ddctf (2014-02-13 21:13:22)

Offline

#2 2014-02-13 22:03:34

jlolling
Member
3186 posts

jlolling said:

Re: Java code to open SSH tunnel connection?

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


Talend Certified working for cimt objects AG in Berlin

Offline

#3 2014-02-13 22:27:16

ddctf
Member
213 posts

ddctf said:

Re: Java code to open SSH tunnel connection?

Hi, I started working with this component and then hit a rather strange error that I've never seen before:

Exception in component tMysqlRow_1
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (4739923 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
	at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:605)
	at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1078)
	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2412)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2445)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2230)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:813)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
[statistics] disconnected
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
	at java.sql.DriverManager.getConnection(DriverManager.java:579)
	at java.sql.DriverManager.getConnection(DriverManager.java:221)
	at ourworkspace.testingssh_0_1.TestingSSH.tMysqlRow_1Process(TestingSSH.java:703)
	at ourworkspace.testingssh_0_1.TestingSSH.tSshTunnel_2Process(TestingSSH.java:375)
	at ourworkspace.testingssh_0_1.TestingSSH.runJobInTOS(TestingSSH.java:1060)
	at ourworkspace.testingssh_0_1.TestingSSH.main(TestingSSH.java:925)

The max_allowed_packet variable was adjusted (though it's never been a problem before); I feel like this error might be bogus and something else might be going on, but I'm not sure

Last edited by ddctf (2014-02-13 22:27:48)

Offline

#4 2014-02-13 22:34:16

jlolling
Member
3186 posts

jlolling said:

Re: Java code to open SSH tunnel connection?

Did you tested the communication with a hand made tunnel?


Talend Certified working for cimt objects AG in Berlin

Offline

#5 2014-02-13 22:41:54

ddctf
Member
213 posts

ddctf said:

Re: Java code to open SSH tunnel connection?

Yes I can connect in terminal using ssh and can query successfully

Offline

#6 2014-02-14 01:15:16

jlolling
Member
3186 posts

jlolling said:

Re: Java code to open SSH tunnel connection?

As an alternative way you could call the necessary commands to the OS by the tSystem component.


Talend Certified working for cimt objects AG in Berlin

Offline

#7 2014-02-14 18:20:29

ddctf
Member
213 posts

ddctf said:

Re: Java code to open SSH tunnel connection?

Hi thanks for the suggestion

Is this the right idea for tSystem commands?

1. Connect to remote server
2. Start MySQL
3. Enter my MySQL query

Then pass the resulting data on to my next component (e.g. tMap) via Main row connector?

Offline

#8 2014-02-15 16:18:51

jlolling
Member
3186 posts

jlolling said:

Re: Java code to open SSH tunnel connection?

No I mean something like this:

tSystem (call the necessary ssh command) --(OnSubjobOK)--> tMysqlConnection --(OnSubjobOK)--> ... any mysql comps in flows.


Talend Certified working for cimt objects AG in Berlin

Offline

#9 2014-08-08 18:40:45

muazmaz
Member
3 posts

muazmaz said:

Re: Java code to open SSH tunnel connection?

Hi, Can you give more detail of how to use tSystem and tMysqlconnection or if anyone has used it can give snapshot of the settings?

Offline

#10 2017-04-08 00:48:10

cacak
Member
9 posts

cacak said:

Re: Java code to open SSH tunnel connection?

jlolling wrote:

No I mean something like this:

tSystem (call the necessary ssh command) --(OnSubjobOK)--> tMysqlConnection --(OnSubjobOK)--> ... any mysql comps in flows.

your fiest component is System or there is a tSSH before it?

I have a problem to connect to Mysql with ssh.

Offline

#11 2017-04-08 00:51:44

cacak
Member
9 posts

cacak said:

Re: Java code to open SSH tunnel connection?

jlolling wrote:

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.

Offline

Board footer

Talend Contributor Agreement - Talend Website Privacy Policy