0

I create spring project to do the CRUD to the postgres database server but get some error.

HHH000342: Could not obtain connection to query metadata

org.postgresql.util.PSQLException: The connection attempt failed. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:313) ~[postgresql-42.3.1.jar:42.3.1] at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.3.1.jar:42.3.1] at org.postgresql.jdbc.PgConnection.(PgConnection.java:225) ~[postgresql-42.3.1.jar:42.3.1] at org.postgresql.Driver.makeConnection(Driver.java:466) ~[postgresql-42.3.1.jar:42.3.1] at org.postgresql.Driver.connect(Driver.java:265) ~[postgresql-42.3.1.jar:42.3.1] at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar:na]

Here is my application.properties

spring.datasource.url=jdbc:postgresql://3.1.84.18:5432/postgres

spring.datasource.username=postgres

spring.datasource.password=postgres

spring.jpa.database-platform= org.hibernate.dialect.PostgreSQLDialect

spring.jpa.hibernate.ddl-auto=none spring.jpa.show-sql=true

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

my pom.xml

enter image description here

2
  • thank, in file pg_hba.config we update the " host all all 0.0.0.0/0 md5". I changed from ident to md5 authentication method, it works! Commented Feb 20, 2022 at 15:27
  • Please do not post (XML) code as images. See here for more details why: meta.stackoverflow.com/questions/285551 Commented Feb 21, 2022 at 7:35

2 Answers 2

0

Your pom.xml is correct

<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <scope>runtime</scope>
</dependency>

After you must create a postgre user with a password, and then create a postgre database

And on your application.properties, you can use the user created with his password

spring.datasource.database-platform=org.hibernate.dialect.PostgreSQLDialect 
spring.datasource.url=jdbc:postgresql://localhost:5432/database_name
spring.datasource.username=user_name
spring.datasource.password=user_password
spring.jpa.hibernate.ddl-auto=update
Sign up to request clarification or add additional context in comments.

1 Comment

my issues is, after trying to resolve "not connected to the database", I changed the pg_hba.conf with host all all 0.0.0.0/0 ident we retry with host all all 0.0.0.0/0 md5, and issues resolved. thank you
0

my issues is, after trying to resolve "not connected to the database", I changed the pg_hba.conf with host all all 0.0.0.0/0 ident we retry with host all all 0.0.0.0/0 md5, and issue got resolved.

thank you

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.