SQLiteDatabase
管理类,用于数据库层面的操作。
-
openDatabase:打开指定路径的数据库。
-
isOpen:判断数据库是否已打开。
-
close:关闭数据库。
-
getVersion:获取数据库的版本号。
-
setVersion:设置数据库的版本号。
事务类,用于事务层面的操作。
-
beginTransaction:开始事务。
-
setTransactionSuccessful:设置事务的成功标志。
-
endTransaction:结束事务。
数据处理类,用于数据表层面的操作。
-
execSQL:执行拼接好的SQL控制语句。
-
delete:删除符合条件的记录。
-
update:更新符合条件的记录。
-
insert:插入一条记录。
-
query:执行查询操作,返回结果集的游标。
-
rawQuery:执行拼接好的SQL查询语句,返回结果集的游标
SQLiteOpenHelper
新建一个继承自 SQLiteOpenHelper 的数据库操作类,提示重写 onCreate 和 onUpgrade 两个方 法。
-
封装保证数据库安全的必要方法。
-
提供对表记录进行增加、删除、修改、查询的操作方法
展示
数据库数据
查询
实体类
User.java
package com.example.datastorage.enity;
public class User {
public int id; // 序号
public String name; // 姓名
public int age; // 年龄
public long height; // 身高
public float weight; // 体重
public boolean married; // 婚否
public User(){
}
public User(String name, int age, long height, float weight, boolean married) {
this.name = name;
this.age = age;
this.height = height;
this.weight = weight;
this.married = married;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", height=" + height +
", weight=" + weight +
", married=" + married +
'}';
}
}