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:
- Prepare the working environment .
- Create an Azure Database for PostgreSQL instance.
- Configure a firewall rule for your PostgreSQL server.
- Configure a PostgreSQL database.
- Create a new Java project.
- Prepare a configuration file to connect to Azure Database for PostgreSQL.
- Create an SQL file to generate the database schema.
- Connect to the database.
- Create a domain class.
- Insert data into Azure Database for PostgreSQL.
- Reading data from Azure Database for PostgreSQL.
For complete info you can refer this doc.