1
votes

Was wondering, what steps am I missing to get a jdbc embeded h2 database working in my play application? Following these docs.

  1. So far editted Application.conf file to contain this: db.default.driver=org.h2.Driver db.default.url="jdbc:h2:databases/test" db.default.user=test db.default.password="testtest"
  2. Next I created a libs directory and added the jar file h2-1.3.174.jar Is this necessary or does the provided driver handle all types of h2 databases (embeded and server - I know it handles in memory)?
  3. Now in the controler how can I access the database? Do I have to start/shutdown the database?
  4. I know I can get connections from the getConnection() method in play.db. But everytime I execute a statement through this connection I get an exception saying no data is available. If I then check - looks like directory databases/test was not created so no database files exist.

What am I missing?

2

2 Answers

1
votes

H2 works out of the box. Just create a new project in the terminal.

Otherwise, to your listing:

  1. I think you should change db.default.url="jdbc:h2:databases/test" to db.default.url="jdbc:h2:mem:play"
  2. don't need to create lib directories. It's all handeled by the build in dependency mgmt sbt
  3. Just use the model objects and call save/update. No need to call start/shutdown
  4. you are in a framework, it's all there ready for you...

I think you should start reading the documentation from the beginning to the end and examine the example applications. It's all there what you are looking for.

1
votes

In addition to myborobudur's answer I'll only mention, that you don't need to use memory database, as you can for an instance use file storage (Embedded) or even run H2 as a server and then connect to it with TCP in Server Mode... Everything is clearly described in H2 documentation.