Connected to DB using ssh, JDBC refuses connection
I added my connection successfully to IntelliJ and I'm able to see my DB schemas. However when I try to run my application, it fails on getConnection()
I'm pretty sure I have it set up correctly as I have the URL copied from the IntelliJ DB connection properties window, are there extra steps required for ssh tunneling to work? Because I have the feeling that JDBC is trying to access the database locally rather than through the ssh tunnel.
URL from properties window: jdbc:postgresql://localhost:5432/<dbname>
Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/<dbname>", username, password);
org.postgresql.util.
Thank you!
Please sign in to leave a comment.
SSH tunnel works only for the IDE features, it's not enabled for your code. If you need to connect via a tunnel, create it externally using command line SSH or adjust your code so that it creates the tunnel when needed.
If you are on Windows, a tool like https://www.bitvise.com/ssh-client may simplify the tunnel creation for code debugging.
As I suspected, thank you very much!
I guess I got the wrong idea from this post https://stackoverflow.com/questions/29725291/how-can-i-do-the-equivalent-of-the-intellij-database-ssh-tunnelling-in-my-own-co