在创建Android应用本地数据库数据库、Android

由网友(三分醉七分醒)分享简介:根据 http://developer.android.com/指南/主题/数据/数据​​storage.html#DB 好像我需要另一个Java类文件(我做),但现在我碰到一个相当悲哀的问题:我不知道如何处理它。 Based on http://developer.android.com/guide/topics/...

根据 http://developer.android.com/指南/主题/数据/数据​​storage.html#DB 好像我需要另一个Java类文件(我做),但现在我碰到一个相当悲哀的问题:我不知道如何处理它。

Based on http://developer.android.com/guide/topics/data/data-storage.html#db it seems like I'd need another Java Class file (which I made), but now I've run into a rather sad problem: I'm not sure how to handle it.

我将如何把它在我的主要活动,并将它只有一次创建数据库,或将尝试重新创建数据库每次运行时?

How would I call it in my main activity and would it only create the database once, or would it try to re-create the database every time it runs?

推荐答案

这仅是第一次将创造的数据库。该后可以使用该SQLiteOpenHelper类的一个对象来访问该​​数据库。请注意,您不必担心数据库的娱乐,如果你使用SQLiteOpenHelper Android的方式会照顾的。

This would 'create' the database only for the first time. After that you can use an object of that SQLiteOpenHelper class to access that database. Note that you don't have to worry about the recreation of the database, android will take care of that if you use the SQLiteOpenHelper approach.

服用数据存储转发的例子,你会创建一个对象,再使用该getWriteableDatabase方法来获取对数据库的写入权限

Taking the data-storage example forward you would create an object of that and then use the getWriteableDatabase method on that to get write access to the database

DictionaryOpenHelper myDictionary;
myDictionary = new DictionaryOpenHelper(this);
SQLiteDatabase db = myDictionary.getWritableDatabase();

//to enter values in the db
ContentValues values = new ContentValues();
values.put("name","Rhyno");
db.insert(nameOfTable, null, values);

有关更详细的示例,请参阅本教程: http://marakana.com /forums/android/examples/55.html

For a more detailed example please refer to this tutorial: http://marakana.com/forums/android/examples/55.html

阅读全文

相关推荐

最新文章