14

I'm trying to access my application's tables in Play! Framework, but I can't find it using the console. For instance, I have two entity models: Address and Campus.

I can create objects and save normally, but I would like to see the changes in fs or mem DB, but the H2 console doesn't show the tables Address and Campus. I'm using the default settings to log in localhost:9000/@db.

What am I doing wrong?

Thanks in advance.

2
  • I don't know the play framework so far... what is your database URL (if there is a database URL in this framework)? Jun 7, 2011 at 14:14
  • Thanks for this, this is a H2 Gui for PlayFramework, saved me a lot of work looking for a GUI! Sep 12, 2011 at 11:59

4 Answers 4

18

The correct URL for the inmemory database is:

jdbc:h2:mem:name-of-your-play-db
1
  • the url is logged in the logging information and you can grab it from there. Jan 9, 2014 at 3:02
10

Steps I took to get a filesystem H2 database console working where my app is in c:\play\myapp:

  1. Go to localhost:9000/@db
  2. Choose the Generic H2 Server option in the first box
  3. For the url enter jdbc:h2:file:c:/play/myapp/db/h2/play
  4. Username is sa password is blank
1
  • Yes, don't do what I did and add the .h2 extension to the play filename in step 3! Sep 12, 2011 at 12:15
0

Most likely the problem is the database URL, so your application and the H2 Console are using different databases. I suggest to use a database URL of the form jdbc:h2:~/data/test or (maybe even better) using an absolute path of the form jdbc:h2:/data/test, or when using Windows even with drive letter: jdbc:h2:c:/data/test. See the documentation about where the database files are stored.

3
  • is that for just the filesystem method? If I am going to do filesystem, I mine as well use postgres....BUT I would love to connect to the in-memory one just cause it's so fast(no disk i/o). Feb 12, 2012 at 16:58
  • never mind, didn't know localhost:9000/@db was a url you could use that actually works!!!! and just hit connect button. of course, I got an internal error as I had H2 console running....can't do that for some reason. Feb 12, 2012 at 17:04
  • I didn't fully understand what your wrote... but keep in mind that when using jdbc:h2:tcp://localhost:9000/@db it is relative to the current working directory of the server. An absolute directory would be jdbc:h2:tcp://localhost:9000//data/test (two slashes after :9000). Feb 13, 2012 at 11:47
0

My five cents. In my case (Unix OS) I just managed to make it work using ~/ in my persistence.xml:

<property name="javax.persistence.jdbc.url" value="jdbc:h2:~/data/testxdb" />

In this way the Database was created in: /Users/lm2a/data/testxdb.mv.db and starting the console with

java -jar h2-2.1.214.jar

Finally I could see my Tables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.