开发者

Populating SQLiteDB with initial values

My app uses a database, it comes pre-populated with about 50 values. I'm accomplishing this by doing about 50 db.execSQL("INSERT INTO....开发者_运维百科 statements in the onCreate section of my DbHelper class.

I was wondering if there was a more ideal way to handle the insertion of initial values or if this was perfectly acceptable.


You can add more than one value set at the same time into a single table:

INSERT INTO mytable (column_a, column_b)
VALUES (val_1, val2), (val_3, val_4), etc

This will perform much faster and be more concise!

Also you may want to consider loading this data from a properties file or similar so it's more easily changed should those initial values ever vary.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜