如何在Play Framework中使用持久H2数据库,而不是在内存中

问题描述:

Java Todo List教程中使用的H2数据库如下:

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"

如何修改配置文件以使用持久性数据库而不是内存版本。我需要设置一个完全独立的数据库,还是可以修改 db.default.url 属性?

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?

我正在使用Play! 2.0.3。

I'm using Play! 2.0.3.

我找到了解决方案。

要创建文件数据库,请修改以下内容:

To create a file database, modify the following:

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

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

其中 data / db into:

data / 数据库文件相对于项目根目录的文件夹位置。

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

db 数据库文件的名称。

db The name of your database files.