Java 如何连接到 H2 中的特定架构

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28547382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 06:23:52  来源:igfitidea点击:

How to connect to specific Schema in H2

javah2

提问by Acewin

So I have created a few schema in H2. How can I connect to a specific schema in H2

所以我在 H2 中创建了一些模式。如何连接到 H2 中的特定模式

For example when I need to connect to a specific schema in SQL Server I have below JDBC URL jdbc:sqlserver://HOSTNAME:PORT;SelectMethod=cursor;instanceName=MYSCHEMA;databaseName=DBNAME

例如,当我需要连接到 SQL Server 中的特定架构时,我有以下 JDBC URL jdbc:sqlserver://HOSTNAME:PORT;SelectMethod=cursor;instanceName=MYSCHEMA;databaseName=DBNAME

Is this feature available in H2. If not is there a workaround.

此功能在 H2 中可用吗?如果没有,是否有解决方法。

I do not want to always access a particular table in my schema instance be accessed like MYSCHEMA.TABLE_NAME

我不想总是像 MYSCHEMA.TABLE_NAME 一样访问我的架构实例中的特定表

Otherwise I suppose only way out will be to create all table into the default schema that is public

否则我想唯一的出路是将所有表创建到公共的默认模式中

采纳答案by Rohit S

There is such feature supported. See this:

有这样的功能支持。看到这个:

http://www.h2database.com/html/grammar.html#set_schema

http://www.h2database.com/html/grammar.html#set_schema

You can specify the schema in the connection string:

您可以在连接字符串中指定架构:

jdbc:h2:test;SCHEMA=SCHEMA_NAME

You can also change the current schema with:

您还可以使用以下命令更改当前架构:

SET SCHEMA SCHEMA_NAME;

Hope this helps.

希望这可以帮助。

回答by T-Gergely

You can also supply a schemaproperty in the infoparameter of

您还可以在info参数中提供架构属性

java.?sql.?DriverManager.getConnection(String url, Properties info).