2

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.

  1. DBeaver I am using a SSL tunnel tab and
  2. I am using a pem file, and user and password

Postgres local connectionenter image description here

  1. The Virtualbox is set to forward port as follows

Postgres Virtualbox port forwardenter image description here

My Java code without ssl tunnel is this

DriverManager.getConnection("jdbc:postgresql://localhost:5432/dbName?user=postgresuser&password=givepassword");

This is failing saying pg_hba.conf not found etc or if I give ssl=true 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.]

5
  • can you post the java code? Commented Jun 27, 2017 at 15:21
  • I dont have any other except above: this one connects :: DriverManager.getConnection("jdbc:postgresql://localhost:5432/dbName?user=postgresuser&password=givepassword"); Commented Jun 27, 2017 at 15:34
  • does this work - stackoverflow.com/questions/16835761/postgresql-via-ssh-tunnel Commented Jun 27, 2017 at 15:36
  • It already works, I am able to connect. The issues is not if i can connect or not. I want code example in Java how to do same. Commented Jun 28, 2017 at 15:12
  • @NxFi did you manage to get a working example to replicate what DBeaver was doing to establish the ssh tunnel? can you share your solution Commented Dec 13, 2021 at 19:55

1 Answer 1

0

You may try using jsch which is an implementation of SSH in Java.

Here is a complete example of how to do it https://cryptofreek.org/2012/06/06/howto-jdbc-over-an-ssh-tunnel/

Note that in this case all your traffic will go to the proxy hence you need to close the session after reading/writting to the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.