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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With