[2.0]H2 memory database browser

4,020 views
Skip to first unread message

Thomas Felix

unread,
Feb 9, 2012, 7:04:42 PM2/9/12
to play-framework
Hi folks,

is something similar to the database browser in play 1.2 already in
play 2.0? localhost:9000/@db just gives me an ACTION NOT FOUND error.

many thanks and regards,
Thomas Felix

Guillaume Bort

unread,
Feb 10, 2012, 3:45:50 AM2/10/12
to play-fr...@googlegroups.com
You can launch the H2 Browser from the console:

h2-browser

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>

--
Guillaume Bort

Thomas Felix

unread,
Feb 10, 2012, 7:29:54 AM2/10/12
to play-framework
Hi Guillaume,

many thanks for the reply. I tried this and yesterday I used the stand-
alone version from the h2 website as well.
But even with your solution it gives me just the INFORMATION_SCHEMA
tables, no trace of the tables which play generates (of course
I have loaded and applied the db evolution ;)) it seems the browser
uses a different instance of the memory database instead of using
the database which is created by play... but maybe this is more of a
H2 issue instead of a play problem?

In case this doesnt work out I have to use a mysql db and just use
this with other browsing tools... :/

On Feb 10, 9:45 am, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> You can launch the H2 Browser from the console:
>
> h2-browser
>
> On Fri, Feb 10, 2012 at 1:04 AM, Thomas Felix
>

Guillaume Bort

unread,
Feb 10, 2012, 7:33:14 AM2/10/12
to play-fr...@googlegroups.com
It should work. Are you sure that you connect to the same h2 database?

> In case this doesnt work out I have to use a mysql db and just use
> this with other browsing tools... :/

Anyway you can use h2-browser to browse any existing JDBC database. Even mysql.

biesior

unread,
Mar 31, 2012, 7:23:24 AM3/31/12
to play-fr...@googlegroups.com
Thomas you're right.

This behaviour is caused by H2 connection policy:
http://www.h2database.com/html/features.html#in_memory_databases (paragraphs 2 - 4)

in short: "Opening two connections within the same virtual machine means opening two different (private) databases."

there are two solutions:

  • first, very fast and very... uncomfortable is:
    open first Play console, then from within play console run the h2-browser and at the end run the app (and perform DB evoulutions of your app). Then you can access with the same url as given in application.conf
  • but better way is just to use url suggested by H2 docs:
    • run your Play app and perform evolutions as usually
    • copy your db url (let's say: jdbc:h2:mem:yourapp )
    • Access it from any H2 browser or even  IDE's Data Sources tab with modified url:
      jdbc:h2:tcp://localhost/mem:yourapp

Thomas Felix

unread,
Mar 31, 2012, 3:42:22 PM3/31/12
to play-fr...@googlegroups.com
Thank you for the late reply, in the meantime I used mysql but this will make it a bit simpler, I will try it out when I need to check the data inside the database again. ;)

sas

unread,
Apr 1, 2012, 2:51:52 AM4/1/12
to play-framework
I have the same problem, but that solution didn't work for me

I tried with

1-

$ play

h2-browser

run

(apply evolution)

then back to h2-browser login screen

controller: org.h2.Driver
url jdbc: jdbc:h2:mem:play
username: sa
password

but it appears in a clean db

---

2-

I don't understand what should I put in my url, I can't enter
"jdbc:h2:tcp://localhost/mem:yourapp" in my browser... what do you
mean with modified url???

...

So, in the end, how can I connect with h2-browser to my in memory h2
db???







On 31 mar, 08:23, biesior <bies...@gmail.com> wrote:
> Thomas you're right.
>
> This behaviour is caused by H2 connection policy:http://www.h2database.com/html/features.html#in_memory_databases
> (paragraphs 2 - 4)
>
> in short: *"Opening two connections within the same virtual machine means
> opening two different (private) databases."*
>
> there are two solutions:
>
>    - first, very fast and very... uncomfortable is:
>    open first Play console, then from within play console run the
>    h2-browser and at the end run the app (and perform DB evoulutions of your
>    app). Then you can access with the same url as given in application.conf
>    - but better way is just to use url suggested by H2 docs:
>       - run your Play app and perform evolutions as usually
>       - copy your db url (let's say: *jdbc:h2:mem:yourapp* )
>       - Access it from any H2 browser or even  IDE's Data Sources tab with
>       modified url:
>       *jdbc:h2:tcp://localhost/mem:yourapp*

sas

unread,
Apr 1, 2012, 3:00:41 AM4/1/12
to play-framework
also tried with several combinations, liek jdbc:h2:tcp://
192.168.1.103:9092/play, but none of them seems to work...


On 1 abr, 03:51, sas <open...@gmail.com> wrote:
> I have the same problem, but that solution didn't work for me
>
> I tried with
>
> 1-
>
> $ play
>
> h2-browser
>
> run
>
> (apply evolution)
>
> then back toh2-browserlogin screen
>
> controller: org.h2.Driver
> url jdbc: jdbc:h2:mem:play
> username: sa
> password
>
> but it appears in a clean db
>
> ---
>
> 2-
>
> I don't understand what should I put in my url, I can't enter
> "jdbc:h2:tcp://localhost/mem:yourapp" in my browser... what do you
> mean with modified url???
>
> ...
>
> So, in the end, how can I connect withh2-browserto my in memory h2
> db???
>
> On 31 mar, 08:23, biesior <bies...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Thomas you're right.
>
> > This behaviour is caused by H2 connection policy:http://www.h2database.com/html/features.html#in_memory_databases
> > (paragraphs 2 - 4)
>
> > in short: *"Opening two connections within the same virtual machine means
> > opening two different (private) databases."*
>
> > there are two solutions:
>
> >    - first, very fast and very... uncomfortable is:
> >    open first Play console, then from within play console run the
> >    h2-browserand at the end run the app (and perform DB evoulutions of your
> >    app). Then you can access with the same url as given in application.conf
> >    - but better way is just to use url suggested by H2 docs:
> >       - run your Play app and perform evolutions as usually
> >       - copy your db url (let's say: *jdbc:h2:mem:yourapp* )
> >       - Access it from anyH2 browseror even  IDE's Data Sources tab with

biesior

unread,
Apr 1, 2012, 5:49:01 AM4/1/12
to play-fr...@googlegroups.com
Sas, I tried to be as clear as possible, therefore Coloured the syntax....

Try this:
open console then h2-browser, then run app and perform evolutions.

next find the web browser window opened by  h2-browser and there you have Login box - put the modified url in JDBC URL field

It works for me perfectly, if you can not figure it out I can not help you more...

sas

unread,
Apr 1, 2012, 1:40:07 PM4/1/12
to play-framework
Thanks a lot, biesior

I don't know what could I've been doing wrong, but now the first
approach works ok

It also works writing to a file, with db.default.url="jdbc:h2:data/db"

I just can't make it work with the second approach, that is with the
integrated tcp server

It opens a new db...

And if I try from a second console, with the data/db, I get

Database may be already in use: "Locked by another process". Possible
solutions: close all other connection(s); use the server mode
[90020-158] 90020/90020 (Ayuda)

So, the problem is I can't find a way to connect from a second JVM.
But the first solution works fine, thanks!

saludos

sas
Reply all
Reply to author
Forward
0 new messages