This is what I am doing... Lets say my remote server is at "dev.myserver.com".
I have MySQL and Tomcat running on it. Port 22 and 80 are open on it.
JSch jsch = new JSch();
jsch.addIdentity("dev.pem");
String user = "root";
String host = "dev.myserver.com";
int sshPort = 22;
Session session = jsch.getSession(user, host, sshPort);
lport = 3306;
rhost = "dev.myserver.com";
rport = 3306;
session.setHost(host);
session.setPassword("");
UserInfo ui = new MyUserInfo();
session.setUserInfo(ui);
session.connect();
int assigned_port = session.setPortForwardingL(lport, rhost, rport);
if (session.isConnected())
{
System.out.println("localhost:" + assigned_port + " -> " + rhost + ":" + rport);
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:"+lport+"/mydb", "root",
"password");
Statement statement = con.createStatement();
ResultSet res = statement.executeQuery("SELECT * FROM category");
while (res.next())
{
String name = res.getString("name");
System.out.println("name: " + name);
}
con.close();
}
The sysout says "localhost:3306 -> dev.myserver.com:3306" so it appears all is
working to that point. Then the system hangs for a while and eventually throws
"com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link
failure Last packet sent to the server was 0 ms ago."
The funny thing is if I change lport and rport to 80 I can point my browser at
http://localhost/ and see the page on the server. The only thing I can think of
is port 80 and 22 are open on the server and 3306 is closed but I thought that
was the whole point of port forwarding, to forward over 22. I can also access
the db using the port forwarding built into SQLyog using the same
configuration.
What am I doing wrong?
Bob
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users