Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Spring JDBCH2模板动态切换模式_Spring Boot_H2_Jdbctemplate - Fatal编程技术网

Spring boot Spring JDBCH2模板动态切换模式

Spring boot Spring JDBCH2模板动态切换模式,spring-boot,h2,jdbctemplate,Spring Boot,H2,Jdbctemplate,我正试图在单元测试期间让h2在内存中切换数据库模式。几乎我所有的数据都在默认的模式PUBLIC中,但为了模拟生产的工作方式,我需要切换到另一个模式SETTINGS进行一次查询 我试图用jdbcTemplate.getDataSource().getConnection().setSchema(“设置”)切换模式 但是当我记录jdbcTemplate.getDataSource().getConnection().getSchema()的值时我得到默认的公共代码。 因此,我的查询失败,因为我得到一

我正试图在单元测试期间让h2在内存中切换数据库模式。几乎我所有的数据都在默认的模式
PUBLIC
中,但为了模拟生产的工作方式,我需要切换到另一个模式
SETTINGS
进行一次查询

我试图用
jdbcTemplate.getDataSource().getConnection().setSchema(“设置”)切换模式
但是当我记录
jdbcTemplate.getDataSource().getConnection().getSchema()的值时我得到默认的公共代码。
因此,我的查询失败,因为我得到一个BadSqlGrammarException,因为我试图查询的表找不到,这是有意义的,因为它位于另一个模式中

有人能帮我解决这个问题吗


谢谢

您可以在表前面加上模式前缀(假设用于连接数据库的用户具有足够的权限),如:

或者,如果可以创建另一个在连接字符串中指定架构的连接


我建议使用前缀,因为这表明您使用的是另一个模式。

嘿,Niki,thx为了提供帮助,我现在使用了您的解决方案,即在表前面加上模式。
SELECT * from SETTINGS.you_other_table;