DbUtils
2015-12-06 11:28
344 查看
1. 创建bean 必须要有id/_id属性(作为表的主键)
2. 使用DbUtils 并建数据库
3. 插入数据
4. 查询数据
5. 修改数据
6. 删除数据
2. 使用DbUtils 并建数据库
// //public static DbUtils create(Context context, String dbName) // dbUtils = DbUtils.create(MainActivity.this, "Student.db");
3. 插入数据
dbUtils.save(new Student("新垣结衣", 27));//插入单条数据(放在try-cath中) dbUtils.saveAll(list);//插入集合数据(放在try-cath中)
4. 查询数据
Student student = dbUtils.findFirst(Selector.from(Student.class).where("name","=","新垣结衣")); //查询符合条件的第一条数据 //import com.lidroid.xutils.db.sqlite.Selector;
List<Student> list = dbUtils.findAll(Selector.from(Student.class) .where("id" ,"<", 54) .and(WhereBuilder.b("age", ">", 20).or("age", " < ", 30)) .orderBy("id") .limit(pageSize) .offset(pageSize * pageIndex)); //查询集合数据
5. 修改数据
try { List<Student> findAll = dbUtils.findAll(Selector.from(Student.class).limit(5)); Student student = findAll.get(0); student.setAge("50"); dbUtils.update(student); } catch (DbException e) { // TODO Auto-generated catch block e.printStackTrace(); }
6. 删除数据
private void dbUtilsDelete() { // TODO Auto-generated method stub try { List<Student> findAll = dbUtils.findAll(Selector.from(Student.class)); //dbUtils.deleteAll(findAll); Student student = findAll.get(0); dbUtils.delete(student); } catch (DbException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
相关文章推荐
- JS中的split
- 隐马尔可夫模型
- LAMP 1.7Apache用户认证
- WPF的Binding学习笔记(一)
- [LeetCode]Largest Rectangle in Histogram
- 基础练习 01字串
- c++ associative container: map and set
- php生成 二维码
- 1070. Mooncake (25)
- Java Word插入图片
- uva 489
- Struts2+AJax判断用户名是否存在
- C#中流程控制语句
- css格式化的基本运用
- 1069. The Black Hole of Numbers (20)
- 【转】设计模式六大原则(3):依赖倒置原则
- python核心编程-partial函数
- 基础练习 闰年判断
- 计算机网络_3_应用层
- 1068. Find More Coins (30)