Home > Mobile >  can't connect to azure postgres db from java running on azure vm
can't connect to azure postgres db from java running on azure vm

Time:11-04

I have a Spring Boot java program running on an azure linux virtual machine. I would like to connect to an azure postgres db. I can connect manually to it using psql on azure cli, but not from java.

There is an older azure postgres db that I am able to connect to from the same java program. I've got the connection parameters to the new db set similarly in application.properties file. I didn't create that database so I'm wondering if there is some property of the db that needs to be set to allow connections from java?

CodePudding user response:

You can connect to Azure Postgres DB from java by using JDBC. Follow the below steps to connect:

  1. Prepare the working environment .
  2. Create an Azure Database for PostgreSQL instance.
  3. Configure a firewall rule for your PostgreSQL server.
  4. Configure a PostgreSQL database.
  5. Create a new Java project.
  6. Prepare a configuration file to connect to Azure Database for PostgreSQL.
  7. Create an SQL file to generate the database schema.
  8. Connect to the database.
  9. Create a domain class.
  10. Insert data into Azure Database for PostgreSQL.
  11. Reading data from Azure Database for PostgreSQL.

For complete info you can refer this doc.

  • Related