I get a "Communications link failure" error in this line of code:
mySqlCon = DriverManager.getConnection("jdbc:mysql://**server ip address**:3306/db-name", "mu-user-name", "my-password");
I checked everything in this post :
- I increased the max-allowed-package in my.cnf to etc / mysql: max_allowed_packet = 5073741824 ------ [mysqldump] max_allowed_packet = 1G
- Binding Address: 127.0.0.1
- All timeout values ββare equal to the number
- Tomcat is not yet installed on the server (new server)
- There are no skip networks in my.cnf
- I can execute a ping server
- I am connected to mysql database via ssh
When I change the query string to this:
mySqlCon = DriverManager.getConnection("jdbc:mysql://**server ip address**:22/127.0.0.1:3306/db-name", "mu-user-name", "my-password");
I get the error message Packet for query is too large (4739923 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable. Packet for query is too large (4739923 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
So far I have resized the package to my.cnf and restarted the mysql service after that.
Any suggestions?
Note:
I can connect via ssh with this code, but this method does not seem rational! I can connect once basically, and then I have to pass the connection to all classes.
public my-class-constructor() { try { go(); } catch (Exception e) { e.printStackTrace(); } mySqlCon = null; String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://" + rhost + ":" + lport + "/"; String db = "my-db-name"; String dbUser = "dbuser"; String dbPasswd = "pass"; try { Class.forName(driver); mySqlCon = DriverManager.getConnection(url + db, dbUser, dbPasswd); } catch (Exception e) { e.printStackTrace(); } } public static void go() { String user = "ssh-user"; String password = "ssh-pass"; String host = "ips-address"; int port = 22; try { JSch jsch = new JSch(); Session session = jsch.getSession(user, host, port); lport = 4321; rhost = "localhost"; rport = 3306; session.setPassword(password); session.setConfig("StrictHostKeyChecking", "no"); System.out.println("Establishing Connection..."); session.connect(); int assinged_port = session.setPortForwardingL(lport, rhost, rport); System.out.println("localhost:" + assinged_port + " -> " + rhost + ":" + rport); } catch (Exception e) { System.err.print(e); e.printStackTrace(); } }
Andi source share