在 Spring Boot 项目中,我尝试从 IDE 查看内存中的表。
如何从 Intellij IDEA 访问内存中的 h2 数据库。
这是我的一个片段应用程序.yml:
h2:
datasource:
url: jdbc:h2:mem:mydb
username: username
password: 123
driver-class-name: org.h2.Driver
init-sql: h2.sql
console:
enabled: true
path: /search/console
settings:
trace: false
web-allow-others: false
Intellij has no field to input username for in-memory database:
Test Connection shows success, however it doesn't see tables from h2.sql.
I can access them using h2 console.
请记住,这可能会显示数据库,但不会显示表,因为它们会显示仅在 h2 控制台中可见。为了通过 IntelliJ 访问它们,您可能需要将 url 和连接更改为文件类型而不是内存中.
所以代替这个:
#spring.datasource.url=jdbc:h2:mem:testdb
你会有这样的东西:
spring.datasource.url=jdbc:h2:file:~/Users/yourUser/IdeaProjects/resume-portal/src/main/resources/data/resume-portal;MV_STORE=false;AUTO_SERVER=TRUE
然后从 url 创建数据源后
您现在应该可以看到数据库及其表。
如果您使用新的 URL 进行连接,仍然可以从控制台获得该信息。
PS: If'd prefer to use a relative path you can change the url to be something similar to jdbc:h2:file:./src/main/resources/data/resume-portal;MV_STORE=false;AUTO_SERVER=TRUE
这是应用程序的 application.yml 文件。
spring.jpa.defer-datasource-initialization=true
#spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.url=jdbc:h2:file:./src/main/resources/data/resume-portal;MV_STORE=false;AUTO_SERVER=TRUE
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.datasource.username=sa
spring.datasource.password=
spring.sql.init.mode=always
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)