其他工具无法访问内存数据库中的 Spring Boot [英] Spring Boot in memory database not accessible from other tools

查看:37
本文介绍了其他工具无法访问内存数据库中的 Spring Boot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Intellij 控制台访问内存中的 H2 数据库.我正在使用 spring boot 来配置一切.连接字符串为:spring.datasource.url=jdbc:h2:mem:testdb

I am trying to access an in memory H2 database from the intellij console. I'm using spring boot to configure everything. The connection string is: spring.datasource.url=jdbc:h2:mem:testdb

当我使用 intellij 连接到数据库时,我无法查看或查询表.我可以运行一个创建表命令来获取它,但就是这样.这是该配置的图像:

When I connect to the database using intellij I can't see or query the tables. I can run a create table command to get it but that is it. Here is an image of that config:

SHOW TABLES 查询的结果不返回任何内容.

The result of a SHOW TABLES query returns nothing.

为什么我无法连接到这个数据库?

Why can't I connect to this database?

推荐答案

当使用像 H2 或 HSQLDB 这样的内存数据库时,内存实例只能从应用程序访问.

When using an in-memory database like H2 or HSQLDB that in-memory instance is only accessible from the application.

如果您想要共享数据库(以便您可以看到其中的内容),您必须在 [服务器模式][2] 下启动它或改用基于文件的模式 (jdbc:h2:~/your-db).

If you want to have a shared database (so that you can see what is inside it) you have to start it in [server mode][2] or use a file based mode instead (jdbc:h2:~/your-db).

这篇关于其他工具无法访问内存数据库中的 Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆