Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

Why I can't find my tables in H2 schema / How can I validate which H2 schema my Spring boot app is working with?

I'm running a spring boot app

didn't have any setting for h2 other than maven

when i'm connecting to the h2 console i can see the tables that were supposed to be created for two entities

i connected with the JDBC URL: jdbc:h2:mem:testdb (which is supposed to be the default)

Is there a way to make sure what schemas is H2 currently running/ or some log file for H2 ?

in my application.properties i have this:

spring.h2.console.enabled=true
spring.h2.console.path=/h2

I read somewhere that H2 initializing itself upon login, but a demo i was watching these were the exact steps taken , so not sure that is the case.

these are the settings in the H@ console:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can explicitly instruct spring boot to create and connect to a particular schema in H2 with config as below.

spring.datasource.url=jdbc:h2:~/test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=sa

This creates a datasource of name test database in h2 in file mode. There would be a file called test.db in your home folder which would be the data file for the database.

DB_CLOSE_ON_EXIT property decides to recreate the database on every restart.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...