1

I just configured new project with https://start.spring.io/ My 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>

and my 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

I got an error org.postgresql.util.PSQLException: FATAL: database "tower" does not exist. It says that my database is not up but I can easily get into it with pgAdmin3/4 and runs queries. I also use localhost:5432 with database name tower, user postgres and my password which is correct for sure. Why then I got and error that my database is not up. I also tried:

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

and got exactly the same error- database "tower" does not exists. Why I got such an error when database is up?

2
  • Do you have multiple installation of Postgres an running ?, There is possibility that you may connected to different DB. Commented Apr 7, 2018 at 10:57
  • VERSION = PostgreSQL 9.6.8, no other versions of postgresql Commented Apr 7, 2018 at 12:41

2 Answers 2

2

Turn on logging, at least you will see if you're trying to connect in Postgesql. Also try without using PGAdmin, like using the Squirrel SQL client which, unlike PGAdmin, will require you to set up the connection exactly how you describe ie URL = jdbc:postgresql://localhost:5432/tower If Squirrel connects then it's more like your code than PGAdmin

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I had to set connection as in application.properties and found bug by this - name wasn't /tower. Thank you
2

I know this is an old question but what worked for me is creating the db tower

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.