【问题标题】:Where to add the -ifNotExists flag to h2 start command?在哪里将 -ifNotExists 标志添加到 h2 start 命令?
【发布时间】:2019-10-07 10:35:53
【问题描述】:

我正在关注这个问题。 I am getting error after opening the h2 database console, i enter database name but it is showing database not found errir

我也有同样的问题。用户@joelittlejohn 提供了答案,答案是添加标志 -ifNotExists。但我不知道在哪里添加标志。我无法添加评论,因为它需要 50 分。我是新手,我没有 50 分。所以我不得不在这里问。

我正在关注有关在 Spring Boot 中使用 H2 的教程。我应该在哪里将 -ifNotExists 标志添加到 h2 start 命令?它是添加到 application.properties 文件还是其他地方?

我也试过独立版。如何添加标志?我添加到 h2.bat 但这不起作用。我应该在哪里添加它?

@java -cp -ifNotExists "h2-1.4.199.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Console%*
@if errorlevel 1 pause

【问题讨论】:

    标签: database spring spring-boot h2


    【解决方案1】:

    -ifNotExistsServer 工具的命令行参数。 Console 不支持该选项。您应该像这样更改 bat 文件:

    @java -cp "h2-1.4.199.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Server -ifNotExists 
    

    要使用 Spring Boot 在服务器模式下启动 H2,请参阅这篇文章 How to enable H2 Database Server Mode in Spring Boot。您可以像这样传递选项:

    public Server h2Server() throws SQLException {
            return Server.createTcpServer("-ifNotExists", "-tcpAllowOthers", ...);
    }
    

    您仍然可以在嵌入式模式下运行 H2,在这种情况下,应该默认创建数据库。

    【讨论】:

    • 谢谢,这应该添加到 h2.bat 中吗?以及当我在 Spring Boot 项目中使用 h2 时如何添加标志?它是添加到 application.properties 文件还是其他地方?
    猜你喜欢
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多