[JSch-users] setPortForwardingL not working for MySQL
Status: Alpha
Brought to you by:
ymnk
From: bob m. <dw...@ho...> - 2011-02-15 15:37:39
|
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 |