gpt4 book ai didi

postgresql - 无法从 Spring Boot 应用程序连接到 PostgreSQL 数据库 - FATAL : database does not exist

转载 作者:行者123 更新时间:2023-11-29 13:15:32 25 4
gpt4 key购买 nike

我刚刚用 https://start.spring.io/ 配置了新项目我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>tower</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>tower</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>9</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</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.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>

和我的 application.properties:

spring.datasource.url= jdbc:postgresql://localhost:5432/tower

spring.datasource.username=postgres
spring.datasource.password=XXX


spring.jpa.hibernate.ddl-auto=none

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false

我收到错误 org.postgresql.util.PSQLException: FATAL: database "tower"does not exist。它说我的数据库没有启动,但我可以使用 pgAdmin3/4 轻松进入它并运行查询。我还将 localhost:5432 与数据库名称 tower、用户 postgres 和我的密码一起使用,这肯定是正确的。为什么然后我得到错误消息说我的数据库没有启动。我也试过:

Class.forName("org.postgresql.Driver");
Connection connection = null;
connection = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/tower","postgres", "XXX");

并得到完全相同的错误 - 数据库“tower”不存在。为什么我在数据库启动时会出现这样的错误?

最佳答案

打开日志记录,至少你会看到你是否尝试在 Postgesql 中连接。也可以尝试不使用 PGAdmin,例如使用 Squirrel SQL 客户端,与 PGAdmin 不同,它需要您完全按照您描述的方式设置连接,即 URL = jdbc:postgresql://localhost:5432/tower如果 Squirrel 连接那么它更像是你的代码而不是 PGAdmin

关于postgresql - 无法从 Spring Boot 应用程序连接到 PostgreSQL 数据库 - FATAL : database does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49706401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com