Android:SQLiteOpenHelper 学习笔记
2012-03-11 02:13
441 查看
SQLiteOpenHelper
一个帮助类,用于帮助用户创建数据库和数据库的版本管理。
使用的时候,子类必须实现其onCreate(),onUpgrade()两个方法(这个类是抽象类,这两个方法是抽象方法)。
在打开或操作数据库的时候,必须保证数据库存在。
getReadableDatabase
public SQLiteDatabase getReadableDatabase()
Create and/or open a database. This will be the same object returned by
getWritableDatabase()unless some problem, such as a full disk, requires the database to be opened read-only. In that case, a read-only database object will be returned. If the problem is fixed, a future call to
getWritableDatabase()may succeed, in which case the read-only database object will be closed and the read/write object will be returned in the future.创建或者打开一个数据库。这个和由getWriteableDtabase()方法返回的对象是同一个;有的时候,在磁盘空间已经满的时候,就是只读状态。
getWritableDatabase
public SQLiteDatabase getWritableDatabase()
Create and/or open a database that will be used for reading and writing. Once opened successfully, the database is cached, so you can call this method every time you need to write to the database. Make sure to call
close()when you no longer need it.
Errors such as bad permissions or a full disk may cause this operation to fail, but future attempts may succeed if the problem is fixed.
创建或者打开一个数据库,用于读和写。
在第一次打开成功的时候,数据库将会被打开;(调用 oncreate() onUpgrade() )
在你每次写数据到数据库的时候,都会调用这个方法。
确保你以后不使用的情况下,调用close()方法。
像不健康的许可或者磁盘已满,将会导致方法运行失败,但是在之后问题解决了,将来的操作可能会成功。
onCreate
public abstract void onCreate(SQLiteDatabase db)
Called when the database is created for the first time. This is where the creation of tables and the initial population of the tables should happen.
在数据库第一次创建的时候,调用此方法。表格的创建和表格的初始化,都在这里完成。
相关文章推荐
- 学习笔记 新浪微博篇 三 Android SQLiteOpenHelper 类详解
- android 数据库 SQLiteOpenHelper和ContentProvider学习笔记---添加修改删除数据之联系人(二)
- android 数据库 SQLiteOpenHelper和ContentProvider学习笔记---添加数据及显示(一)
- Android学习篇章23-SQLite数据库操作:SQLiteOpenHelper-单例模式
- 2014-10-27Android学习------SQLite数据库操作(二)-----数据库的创建--SQLiteHelper extends SQLiteOpenHelper
- android学习之-SQLiteOpenHelper的应用
- 【转】Android使用SQLiteOpenHelper对数据库进行版本管理【学习记录】
- android学习记录(十)SQLiteOpenHelper简单解析。
- Android下SQLite3数据库操作笔记(二)之-SQLiteOpenHelper
- Android学习(十) SQLite 基于SQLiteOpenHelper的操作方式
- 【android】SQLite数据库之SQLiteOpenHelper与SQLiteDatabase
- 学习笔记:Android SQLite,并实现SQLite基本CRUD操作的Demo
- Android SQLiteOpenHelper(手机数据库)
- android 移动开发 SQLiteOpenHelper
- Android中的SQLite SQLiteOpenHelper SQLiteDatabase及其例子
- android SQLite SQLiteOpenHelper
- Android如何使用SQLiteOpenHelper
- Android 基础:SQLiteOpenHelper(SQLite的CURD)
- android SQLiteOpenHelper使用示例
- Android开发学习笔记:数据存取之SQLite浅析