Network Design

This is me… trying to access PostgreSQL Database Server, but it doesn’t have public IP

Maybe it’s sound common, but actually my goal is to create Java Program to access PostgreSQL Server that located behind some Site server. This PostgreSQL Server, doesn’t have public IP.. so it can’t accessed from the internet. Just take a look at the network design above.

I’ve heard about JSch (http://www.jcraft.com/jsch/) few years ago, and we can simply read the example and demonstration of its functionality here: http://www.jcraft.com/jsch/examples/. And if we only want to access the Database via SSH, we can simply use this example on stackoverflow: https://stackoverflow.com/questions/1968293/connect-to-remote-mysql-database-through-ssh-using-java.

But, my network design a little bit different. I was thinking about this problem several hours… until someone gave me some advised in Java Group discussion on Facebook: create a tunnel then connect to the db through that tunnel. Eureka!

This is my code snippet.

Continue reading