日期:2014-05-16 浏览次数:20450 次
? Android provides full support for?SQLite?databases. Any databases you create will be accessible by name to any class in the application, but not outside the application. Android 系统对 SQLite 数据库提供了充分的支持. 对于应用程序中的任意一个类, 只要通过名字就可以轻易的访问你所创建的数据库. The recommended method to create a new SQLite database is to create a subclass of? 创建一个新的 SQLite 数据库的推荐方法是: 创建一个 SQLiteOpenHelper 类的子类并重写 onCreate() 方法, 在该方法中执行 SQLite 命令来创建表. 例如: ? ?Using Databases 使用数据库
SQLiteOpenHelper
?and override the?onCreate()
?method, in which you can execute a SQLite command to create tables in the database. For example:public class DictionaryOpenHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 2;
private static final String DICTIONARY_TABLE_NAME = "dictionary";
private static final String DICTIONARY_TABLE_CREATE =
"CREATE TABLE " + DICTIONARY_TABLE_NAME + " (" +
KEY_WORD + " TEXT, " +
KEY_DEFINITION + " TEXT);";
DictionaryOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DICTIONARY_TABLE_CREATE);
}
}