安卓提供了一个SQLiteOpenHelper类,通过继承这个类,并实现自己创建的类的对象,调用这个对象的getReadableDatabase()方法和getWritableDatabase()方法来创建数据库。
数据库中要建表:建表的标准写法
create table tableName
(
id integer primary key autoincrement
name text
price real
)
其中 text代表String real代表double
primary key 代表主键
建表
db.execSQL();
添加数据
db.insert(tablename,null,value)
value是一个ContentValue对象,用来存储将要添加的数据。
查询数据
db.query()返回一个包含查询表内容的cursor容器。
通过读取cursor,把数据查询出来。
最后一定要关闭cursor;