Database not found, and IFEXISTS=true, so we cant auto-create it

后端 未结 17 2903
不思量自难忘°
不思量自难忘° 2020-12-15 06:20

I am getting error after opening the h2 database console. I enter database name but it is showing database not found error:

Database \"C:/Users/Barlek

相关标签:
17条回答
  • 2020-12-15 07:17

    i changed JDBC URL to

    jdbc:h2:mem:testdb

    and it's work

    0 讨论(0)
  • 2020-12-15 07:17

    Adding to @Prateik Upadhyay's answer, if you want to rename your db connection name to something else the only thing that worked for me is below. I am using spring boot 2.2.4 version. with h2 1.4.200 version.

    spring.jpa.hibernate.ddl-auto=create-drop
    spring.datasource.url=jdbc:h2:~/MyComponentDB;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1;MODE=Oracle
    spring.datasource.driverClassName=org.h2.Driver
    spring.datasource.username=sa
    spring.datasource.password=
    spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
    spring.h2.console.enabled=true
    
    0 讨论(0)
  • 2020-12-15 07:21

    use the below properties in the pom.xml and run the application again.

        <?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.in28minutes.database</groupId>
    <artifactId>database-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    
    <name>database-demo</name>
    <description>Demo project for Spring Boot</description>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.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>1.8</java.version>
    </properties>
    
    <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-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </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>
    
    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    

    0 讨论(0)
  • 2020-12-15 07:21

    I faced this issue recently, there were two issues.

    1. By default, it was not populated with in-memory database rather jdbc:h2:~/test.
    2. The db name I configured in the datasource was not test.

    when I changed the JDBC url to jdbc:h2:mem:{db-name-in-config}, it worked like a charm.

    0 讨论(0)
  • 2020-12-15 07:22

    first url to jdbc:h2:mem:testdb second changed the version of Spring Boot to 2.1.3 and it works

    0 讨论(0)
提交回复
热议问题