gpt4 book ai didi

database - H2:如何设置默认模式和数据库?

转载 作者:太空狗 更新时间:2023-10-30 01:47:17 29 4
gpt4 key购买 nike

我正在使用 Liquibase 更新我的数据库并根据 H2 对其进行测试。

我正在使用 Spring 来配置属性。我用

dataSource.setUrl("jdbc:h2:mem:test_common");

连接到 test_common 数据库,但没有成功。

我意识到在 H2 database != Schema 中,所以我尝试将默认模式作为 test_common

dataSource.setUrl("jdbc:h2:mem:test_common;INIT=CREATE SCHEMA test_common\\; SET SCHEMA test_common");

但这没有成功,我看到日志为

INFO 5/26/14 2:24 PM:liquibase: Dropping Database Objects in schema: TEST_COMMON.PUBLIC
INFO 5/26/14 2:24 PM:liquibase: Creating database history table with name: PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: Creating database history table with name: PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: Successfully released change log lock
INFO 5/26/14 2:24 PM:liquibase: Successfully acquired change log lock
INFO 5/26/14 2:24 PM:liquibase: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::h2: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::h2: Table network created
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::h2: ChangeSet liquibase/2014/1-1.xml::05192014.1525::h2 ran successfully in 5ms
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::h2: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: ChangeSet liquibase/2014/1-2.xml::05192014.1525::h2 ran successfully in 5ms
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: Reading from PUBLIC.DATABASECHANGELOG

如何在 H2 中设置默认架构和数据库名称?

最佳答案

默认架构是PUBLIC

作为记录,Commands SET SCHEMA 的 H2 数据库站点页面命令说:

The default schema for new connections is PUBLIC.

该文档还指出您可以在连接时指定默认模式:

This setting can be appended to the database URL: jdbc:h2:test;SCHEMA=ABC

只有一个数据库

对于访问各种数据库,H2不支持CLUSTERCATALOG的SQL标准概念。作为 JDBC URL 的一部分,您连接到一个特定的数据库(目录)。与该数据库的连接仅限于该单一数据库。查看问题,Can you create multiple catalogs in H2? Thomas Mueller 的回答。

您可以打开另一个到另一个数据库的连接,但它将完全独立。

所以谈论“默认数据库”对 H2 数据库没有任何意义。

关于database - H2:如何设置默认模式和数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23877972/

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