background image

他就是

 SQLite 的库文件

# ls

ls

friends.db

方式二:编码方式

(使用更多)

android.content.Context 中提供了函数 , 注: Activity 是 Context 的子类

openOrCreateDatabase () 来创建我们的数据库

db = context .openOrCreateDatabase(

String DATABASE_NAME , int Context. MODE_PRIVATE , null );

String DATABASE_NAME 数据库的名字

Int MODE 操作模式 Context.MODE_PRIVATE 等

CursorFactory 指针工厂 ,本例中传入 null ,暂不用

2, 建表

命令行方式

# sqlite3

sqlite> create table widgets (id integer primary key autoincrement,name text);

3, 插入数据

命令行

 增加,查询数据

sqlite> insert into widgets values(null,'tom');

insert into widgets values(null,'tom');

sqlite> select * from widgets;

select * from widgets;