I have several concurrent + remote Java/MySQL connections to a private cloud server, on a first approach I begun to make these connections (connect, query, close connection) directly to the server's public IP, which worked normally, but it's not the correct approach due to some security configuration that is going to leave the MySQL binding as localhost (won't be able to use the public IP to access it anymore).
So I have to connect to MySQL through an SSH tunnel. I've seen several responses as 'how to make this' with java, like:
Connect to remote MySQL database through SSH using Java
Which are quite clear and understandable, but I still don't understand if I have to open and close the SSH tunnel everytime I need to open and close a MySQL connection, or what could be the troubles that I could find with SSH sessions.
Also any tips on where and how to store SSH the credentials would be highly appreciated. So far I was saving them on HKEY_LOCAL_MACHINE with base64 for the MySQL user, but it doesn't seem secure enough for the SSH credentials.