I'm trying to connect to a database using Java Spring
properties file:
# suppress inspection "UnusedProperty" for whole file
spring.datasource.url=jdbc:postgresql://localhost:5432/student
spring.datasource.username=postgres
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true
pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
error message:
2021-02-19 16:13:25.813 INFO 16315 --- [main] com.zaxxer.hikari.HikariDataSource: HikariPool-1 - Starting...
2021-02-19 16:13:26.864 ERROR 16315 --- [main] com.zaxxer.hikari.pool.HikariPool: HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: FATAL: database "student" does not exist
...
Although I have a database named student, it says the database does not exist. Despite a lot of research, I could not solve this problem.
Note: I did not write any code, I just wrote student class, student service and student controller and tried to connect to the database with properties and run spring boot application.
Try to create new database on pgAdmin 4 manually. Right click on PostgreSQL under Server and Create -> Database -> write your database name. This may solve your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.