package android.database; import android.database.sqlite.SQLiteDatabase; /** * An interface to let the apps define the actions to take when the following errors are detected * database corruption */ public interface DatabaseErrorHandler { /** * defines the method to be invoked when database corruption is detected. * @param dbObj the { @link SQLiteDatabase} object representing the database on which corruption * is detected. */ void onCorruption(SQLiteDatabase dbObj); }
前面两篇简单介绍SQLite数据库,包括SQLiteDatabase,实际项目中应该很少使用SQLiteDatabase的方法来打开数据库,而是继承SQLiteOpenHelper开发子类,并通过该子类的getReadableDatabase(),getWritableDatabase()方法打开数据库。
SQLite是Android提供的一个管理数据库的工具类(工具类这个概念很重要),可用于管理数据库的创建和版本更新。一般扩展他的onCreate(SQLiteDatabase db)和onUpgrate(SQLiteDatabase db, int oldVersion, int newVersion)。这是两个抽象方法。
构造函数和常用方法
SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)