当前位置:Gxlcms > 数据库问题 > SQLite基本操作

SQLite基本操作

时间:2021-07-01 10:21:17 帮助过:2人阅读

1.创建一个数据库,并且打开

SQLite db = OpenOrCreateDatabase("user.db",MODE_PRIVATE,null);

2.创建一个表

db.execSQL("create table Book(_id integer primary key autoincrement,author text,price real,pages integer ,name text)");

3.插入数据

SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("name", "The Da Vinci Code");
values.put("author", "Dan Brown");
values.put("pages", 454);
values.put("price", 16.96);
db.insert("Book", null, values);
values.clear();//清空后可存储多条数据

4.更新数据

values.put("author","kobe")
db.update("Book",values,"_id>?",new String[]{"3"});

5.删除数据

db.delete("Book","pages>?",new String[]{"500"});

6.查询数据

db.rawQuery("select * from Book",null);

  

数据类型(NULL:空值,INTEGER:整值,REAL:浮点值,TEXT:字符串,BLOB:二进制)

SQLite基本操作

标签:

人气教程排行