2

I just started off with Play framework but I'm having trouble executing the very first step. By default, the application.conf has in-memory database as its url

db.default.url="jdbc:h2:mem:play"

I tried changing this to

db.default.url="jdbc:h2:tcp://localhost/c:/Database/MyPlayDB" 

after seeing this answer but my application does not run after making that change. The error which I get is

Error in custom provider, Configuration error: Configuration error[Cannot connect to database [default]]

Can somebody tell me if I need to make any other change or point me in the right direction?

Thanks!

Community
  • 1
  • 1
Aadithya
  • 189
  • 1
  • 4
  • 18
  • Could you please show us your META-INF/persistance.xml and the database part of your application.conf? – Kris Sep 13 '15 at 21:25
  • My persistance.xml is blank and .conf file has the [following](https://www.dropbox.com/s/v5u8powqrwpstkx/DB.PNG?dl=0) for database – Aadithya Sep 13 '15 at 22:39
  • The url might be wrong. You want to store the database into a local file, right? Then use `db.default.url="jdbc:h2:databasefilename"`. – Kris Sep 13 '15 at 22:45
  • So, should databasefilename be a path on the local machine or just the name ? If its just the name, where does it get created ? – Aadithya Sep 13 '15 at 22:56
  • Both is possible. E.g. with `db.default.url="jdbc:h2:databasefolder/databasefilename"` your database file is stored in a folder 'databasefolder' within your application's root folder. – Kris Sep 13 '15 at 23:05

1 Answers1

3

You did not "Run H2 in server mode" I suppose.

EDIT:

How to run H2 in server mode:

  1. Download H2 from the H2 Downloading page. I use "Platform-Independent Zip" because I am on mac currently.
  2. Unpack it. Let's say to the ~/user/h2 (C:/h2 in the case of windows)
  3. Go to the unpacked folder in terminal and run "java -jar bin/h2*.jar". After this default browser must be opened with the H2 server UI console. URL would be like "http://192.168.0.109:8082/login.jsp?jsessionid=abce6eb1b211a737afe8c2abc6be6390"
  4. You can run application that needs connect to the H2, for example Play application with the setting db.default.url="jdbc:h2:tcp://localhost/c:/Database/MyPlayDB"

Verification on my local installation.

I can run play successfully if I set config to

db.default.url="jdbc:h2:mem:play"

I got "Error in custom provider, Configuration error: Configuration error[Cannot connect to database [default]]" if set config to

db.default.url="jdbc:h2:tcp://localhost/c:/Database/MyPlayDB" 

I can run play successfully if I run H2 in server mode and set config to

db.default.url="jdbc:h2:tcp://localhost/c:/Database/MyPlayDB" 
Andriy Kuba
  • 8,093
  • 2
  • 29
  • 46
  • Could you tell me what I need to do to run it in H2 mode ? Also, I'm expecting the database file to be created when I run my Play application. So, I'm not sure how I can run H2 in server mode if I don't have a database – Aadithya Sep 13 '15 at 14:15
  • Read that answer - it created and you can connect to it by address "jdbc:h2:mem:play". The problem is that you trying to connect to"jdbc:h2:tcp://localhost/c:/Database/MyPlayDB" - so you need to run h2 server independently from play and configure that db. I advice you to use default "jdbc:h2:mem:play" or read how to run h2 as a server (there is the link in that ansver) – Andriy Kuba Sep 13 '15 at 18:37
  • I don't have the option of using in-memory db. I have been looking into running h2 server but it totally conflicts with the steps that we have been given. Apparently none of this is required. However, I looked into `import org.h2.tools.Server; // start the TCP Server Server server = Server.createTcpServer(args).start(); ... // stop the TCP Server server.stop();` from the documentation but I'm not sure where in my play application this has to be plugged in. COuld you throw some light on it ? – Aadithya Sep 13 '15 at 18:41
  • Look at my Edit section – Andriy Kuba Sep 13 '15 at 19:34
  • You don't have to run an external H2 server. As far as I understand Aadithya wants to store the database in a file. For this you can just use `db.default.url="jdbc:h2:databasefilename"` in your `application.conf`. But you have to configure your persistance-unit in `persistance.xml`. – Kris Sep 13 '15 at 21:34
  • Correction to my previous comment: You have to configure persistance.xml only if you want to use JPA. – Kris Sep 13 '15 at 22:40