title: Postgresql Java jdbc connect via SSL tunnel to a DB running in Virtualbox using .pem file
body: <p>Hi I am trying to connect to a local Postgres Db running in Virtualbox Centos, which connects through SSL tunnel. Example of how I connect via DBeaver is below.</p>
  
  <ol>
  <li>DBeaver I am using a SSL tunnel tab and</li>
  <li>I am using a pem file, and user and password</li>
  </ol>
  
  <p>Postgres local connection<a href="https://i.stack.imgur.com/7xmB6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7xmB6.png" alt="enter image description here"></a></p>
  
  <ol start="3">
  <li>The Virtualbox is set to forward port as follows</li>
  </ol>
  
  <p>Postgres Virtualbox port forward<a href="https://i.stack.imgur.com/ewmim.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ewmim.png" alt="enter image description here"></a></p>
  
  <p>My Java code without ssl tunnel is this</p>
  
  <p><code>DriverManager.getConnection("jdbc:postgresql://localhost:5432/dbName?user=postgresuser&amp;password=givepassword");</code></p>
  
  <p>This is failing saying <code>pg_hba.conf</code> not found etc or if I give <code>ssl=true</code> in connection string , says its not supported.. How do I connect to Local DB using ssl tunnel?
  [ My assumption in that pg_hba.conf file would be available on the Virtualbox Host Vm only.]</p>