Accessing play project database with h2-browser

后端 未结 2 1859
滥情空心
滥情空心 2020-12-08 14:47

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

With the configuration below, that I th

2条回答
  •  生来不讨喜
    2020-12-08 15:33

    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)

提交回复
热议问题