title: How to SSH tunnel and connect to a database using IntelliJ and JDBC?
body: <p>I'm having issues connecting to a database hosted on a server using IntelliJ and JDBC. With the command line, the command:</p>
  
  <pre><code>ssh username@server -L 11100:ct1:28017 -N
  </code></pre>
  
  <p>creates a tunnel successfully and the command:</p>
  
  <pre><code>psql db_name -h localhost -p 11100 db_username
  </code></pre>
  
  <p>connects to the database fine and allows me to use it. How would this be translated correctly into the IntelliJ Data Sources and the SSH tunnel tools?</p>
  
  <p>At the moment, for the SSH tunnel settings I have:</p>
  
  <p>Proxy Host: server</p>
  
  <p>Port: 22</p>
  
  <p>Proxy user: username</p>
  
  <p>For the general tab I have:</p>
  
  <p>host: localhost</p>
  
  <p>port: 28017</p>
  
  <p>database: db_name</p>
  
  <p>user: db_username</p>
  
  <p>The connection returns successfully after testing the connection. Inside my program I have:</p>
  
  <pre><code>Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:28017/db_name", user, password);
  </code></pre>
  
  <p>The URL parameter is the one generated by IntelliJ. This however gives me an error "Connection to localhost:28017 refused."</p>
  
  <p>Any ideas on what I am doing wrong?</p>