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
574 views
in Technique[技术] by (71.8m points)

playframework - Accessing play project database with h2-browser

I am having some trouble accessing the mem database via the h2-browser on a Play framework project.

With the configuration below, that I think is the correct one (apparently not!) I am getting a h2-browser, but with no tables (beside schema, that is), even though I have applied some migrations.

What am I missing here? Thanks in advance.

conf/application.conf:

db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.user=sa
db.default.password=""

conf

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

When you are using in-mem databases actually you are accessing two different databases (although with the same path). You have two solutions:

  1. First from your console start bare 'play' console, run h2-browser and finally run your app (withinh the same play console)
  2. Run H2 in server mode, additional beneffit from this approach is fact that you won't loose your data at every app's restart as DB is stored in the file. Then you can access this database from many points (also from 'standalone' H@ browser or some other GUI) with path similar to:

Unix (~ means your home directory)

db.default.url="jdbc:h2:tcp://localhost/~/some/path/to/MyPlayDB"

or Windows

db.default.url="jdbc:h2:tcp://localhost/c:/some/path/to/MyPlayDB"

Note that for best performance in production mode it's worthy switch back to embedded mode, however for dev stage that solution should be good enough (still faster than for an example MySQL)


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

...