1、在AndroidStudio的项目APP的gradle中添加ormLite的库:compile 'com.j256.ormlite:ormlite-android:5.0';
2、创建Bean实体类
1)、创建一个UserBean.java
package com.fengyu.hu.db.bean;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
/**
* Created by Administrator on 2018/2/4.
*/
@DatabaseTable(tableName = "tb_user_bean")
public class UserBean {
@DatabaseField(columnName = "name")
private String name;
@DatabaseField(columnName = "desc")
private String desc;
@DatabaseField(columnName = "age")
private int age;
@DatabaseField(generatedId = true)
private int id;
public UserBean() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
return "UserBean{" +
"name='" + name + '\'' +
", desc='" + desc + '\'' +
", age=" + age +
", id=" + id +
'}';
}
}
其中在UserBean添加@DatabaseTable(tableName = "tb_user_bean")表示这是一张表,tb_user_bean是该表的名字,在属性前添加@DatabaseField(columnName = "age")这个字段,表示在数据库表中列的名称,其中@DatabaseFie