开发者

Grails not preserving my DB data

I am building a small Grails application, and I am trying to make the data persist between server restarts in the development environment.

I changed the relevant part of DataSource.groovy to the following:

development {
    dataSource {
        dbCreate = "update" // one of 'create', 'create-drop','update'
     开发者_如何学JAVA   url = "jdbc:hsqldb:mem:devDB"
    }
}

Every time I restart the server, all the data has disappeared. Am I missing another configuration?

I have tried it both with and without sample data in BootStrap.groovy (if that makes any difference).


... try dropping the 'mem' part of your url string: jdbc:hsqldb:devDB Right now you're running the db in memory mode, hence the loss of data. Running the db in embedded mode should do what you need.


Your url is configured to use an in-memory database. That's what the "mem" in your url string refers to.

I find it easier, especially w/ a small project to use BootStrap.groovy in combination w/ dbCreate="create-drop".

You can change your url to point to a file or relational database, though, if you want to persist w/out using BootStrap.groovy. I'm using grails 2.0 w/ an in memory db.

url = "jdbc:h2:db/devDb;auto_server=true"

Here's an example using mySql (assuming you have a jdbc driver for mysql available):

url = "jdbc:mysql://localhost:8080/foo?autoreconnect=true"

An example w/ file:

url = "jdbc:hsqldb:file:prodDb;shutdown=true"

Hope this helps.


You're using an in-memory database, so there's no way for the data survive across server restarts. Switch to a persistent database (MySQL, Postgres, etc.), then set dbCreate = 'validate'

For example, assuming you chose MySQL as your database you'll need to change the settings in DataSource.groovyto:

development {
    dataSource {
        dbCreate = "validate"

        // Put the MySQL JDBC JAR on the classpath of your Grails app
        driverClassName = "com.mysql.jdbc.Driver"

        // Change these property values as needed
        url = "jdbc:mysql://localhost/yourDB"
        username = "yourUser"
        password = "yourPassword"
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜