關于ormlite增刪改查操作,在這里以一個查詢歷史記錄和根據歷史記錄或當前記錄查詢相關信息進行講解
宣州網站建設公司創(chuàng)新互聯(lián)建站,宣州網站設計制作,有大型網站制作公司豐富經驗。已為宣州上千多家提供企業(yè)網站建設服務。企業(yè)網站搭建\成都外貿網站建設要多少錢,請找那個售后服務好的宣州做網站的公司定做!
增刪改查有很多方法,在這我還是先把工具類代碼粘上,就不作多的解釋啦
public class DataBasehelper extends OrmLiteSqliteOpenHelper {
????private static DataBasehelper db;
????public DataBasehelper(Context context) {
????????super(context, "fwsssssss", null, 8);
????}
?
????@Override
????public void onCreate(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource) {
????????try {
????????????TableUtils.createTable(connectionSource , Om_Em.class);
????????} catch (SQLException e) {
????????????e.printStackTrace();
????????}
????}
?
????@Override
????public void onUpgrade(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource, int i, int i1) {
????????try {
????????????TableUtils.dropTable(connectionSource , Om_Em.class , true);
????????????????onCreate(sqLiteDatabase , connectionSource);
????????} catch (SQLException e) {
????????????e.printStackTrace();
????????}
????}
????public static synchronized DataBasehelper getInstance(Context context){
????????if(db == null){
????????????db = new DataBasehelper(context);
????????}
????????return db;
????}
}
?
然后就是實體類
@DatabaseTable(tableName = "Luck")
public class Om_Em {
????@DatabaseField(generatedId = true)
????int id;
????@DatabaseField
????String name;
????@DatabaseField
????int count;
????@DatabaseField
????int scort;
????@DatabaseField
????int money;
?
????public Om_Em(String name, int count, int scort, int money) {
????????this.name = name;
????????this.count = count;
????????this.scort = scort;
????????this.money = money;
????}
?
????public Om_Em() {
????}
?
????public int getId() {
????????return id;
????}
?
????public void setId(int id) {
????????this.id = id;
????}
?
????public String getName() {
????????return name;
????}
?
????public void setName(String name) {
????????this.name = name;
????}
?
????public int getCount() {
????????return count;
????}
?
????public void setCount(int count) {
????????this.count = count;
????}
?
????public int getScort() {
????????return scort;
????}
?
????public void setScort(int scort) {
????????this.scort = scort;
????}
?
????public int getMoney() {
????????return money;
????}
?
????public void setMoney(int money) {
????????this.money = money;
????}
}
?
然后就是Dao模式了
?
public class Om_Daos {
????Context context;
????public Om_Daos(Context context) {
????????this.context = context;
????}
????public DataBasehelper getHelper(){
????????return DataBasehelper.getInstance(context);
????}
????public Dao
????????????return getHelper().getDao(Om_Em.class);
????}
????public Dao.CreateOrUpdateStatus Update(Om_Em om_em) throws SQLException {
????????return ?getDao().createOrUpdate(om_em);
????}
?
}
?
布局XML代碼如下
????android:id="@+id/list_tab_toolbar" ????layout="@layout/toolbar_main"/> ? ????android:id="@+id/textView5" ????android:layout_width="wrap_content" ????android:layout_height="wrap_content" ????android:layout_alignParentStart="true" ????android:layout_alignParentLeft="true" ????android:layout_alignParentTop="true" ????android:layout_marginStart="196dp" ????android:layout_marginLeft="196dp" ????android:layout_marginTop="139dp" ????android:text="車輛違章居民身份信息查詢" ????android:textColor="#000" ????android:textSize="30dp" /> ? ????android:id="@+id/textView6" ????android:layout_width="wrap_content" ????android:layout_height="wrap_content" ????android:layout_alignParentStart="true" ????android:layout_alignParentLeft="true" ????android:layout_alignParentTop="true" ????android:layout_marginStart="228dp" ????android:layout_marginLeft="228dp" ????android:layout_marginTop="222dp" ????android:text="車牌號" ????android:textSize="20dp" /> ? ????android:id="@+id/sm_4_edit" ????android:layout_width="wrap_content" ????android:layout_height="wrap_content" ????android:layout_alignParentStart="true" ????android:layout_alignParentLeft="true" ????android:layout_alignParentTop="true" ????android:layout_marginStart="326dp" ????android:layout_marginLeft="326dp" ????android:layout_marginTop="212dp" ????android:digits="ABCDabcd0123456789" ????android:ems="10" ????android:inputType="text" /> ?