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();
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;
UserInfo ui = new MyUserInfo();
int assigned_port = session.setPortForwardingL(lport, rhost, rport);
System.out.println("localhost:" + assigned_port + " -> " + rhost + ":" + rport);
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:mydb"+lport, "root", "password");
Statement statement = con.createStatement();
ResultSet res = statement.executeQuery("SELECT * FROM category");
String name = res.getString("name");
System.out.println("name: " + name);
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.
Am I doing something wrong?
Sorry. The db line above should read. Still doesn't work.
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:"+lport+"/mydb", "root", "password");
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.