Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a persistent H2 database in the Play Framework instead of in-memory

The H2 database used in the Java Todo List tutorial is the following:

db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"

How do I modify the configuration file to use a persistent database as opposed to an in-memory version. Do I need to setup an entirely separate DB or can I modify the db.default.url property?

I'm using Play! 2.0.3.

like image 653
Brad Avatar asked Sep 06 '12 02:09

Brad


People also ask

How do I make my H2 database persistent?

If we want to persist the data in the H2 database, we should store data in a file. To achieve the same, we need to change the datasource URL property. In the above property, the sampledata is a file name.

Is H2 an in-memory database?

H2 is an embedded, open-source, and in-memory database. It is a relational database management system written in Java. It is a client/server application. It stores data in memory, not persist the data on disk.

How do I access H2 in-memory database in my browser?

Access the H2 Console You can access the console at the following URL: http://localhost:8080/h2-console/. You need to enter the JDBC URL, and credentials. To access the test database that the greeter quickstart uses, enter these details: JDBC URL: jdbc:h2:mem:greeter-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1.


1 Answers

I found the solution.

To create a file database, modify the following:

From

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

To

db.default.url="jdbc:h2:file:data/db"

Where data/db is broken down into:

data/ The folder location of the database files relative to your project root.

db The name of your database files.

like image 159
Brad Avatar answered Sep 29 '22 02:09

Brad