• 十天冲刺


    今天又系统学习了安卓开发数据库Sqlite的相关知识,相关api操作数据库的具体写法:

    学习视频https://www.bilibili.com/video/BV1wt411n7pz?from=search&seid=5602890916190660679

    按照up主的视频一步步掌握其使用方法

    package com.example.myapplicationgb;
    
    
    import android.content.ContentValues;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    
    import androidx.annotation.Nullable;
    
    public class DatabaseHelper extends SQLiteOpenHelper {
    
        public static final String COST_MONEY = "cost_money";
        public static final String COST_DATE = "cost_date";
        public static final String COST_TITLE = "cost_title";
        public static final String FAMILY_BILL = "family_bill";
    
        public DatabaseHelper(@Nullable Context context) {
            super(context, "family_bill", null, 2);
        }
    
        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL("create table if not exists family_bill(" +
                    "id integer primary key, " +
                    "cost_title varchar, "+
                    "cost_date varchar, "+
                    "cost_money varchar)");
        }
    
        public void insertCost(CostBean costBean){
            SQLiteDatabase database = getWritableDatabase();
            ContentValues cv = new ContentValues();
            cv.put(COST_TITLE,costBean.costTitle);
            cv.put(COST_DATE,costBean.costDate);
            cv.put(COST_MONEY,costBean.costMoney);
            database.insert(FAMILY_BILL,null,cv);
        }
    
        public Cursor getAllCostData(){
            SQLiteDatabase database = getWritableDatabase();
            return database.query(FAMILY_BILL,null,null,null,null,null,"COST_DATE ASC");
        }
    
        public void deleteOne(CostBean costBean)
        {
            SQLiteDatabase database=getWritableDatabase();
            database.delete(FAMILY_BILL,"COST_TITLE = ? and COST_MONEY = ? and COST_DATE = ?", new String[]{""+costBean.costTitle,""+costBean.costMoney,""+costBean.costDate});
        }
        public  Cursor selectlist(String s){
            SQLiteDatabase database =getWritableDatabase();
    //        String sql = "select * from "+ FAMILY_BILL +"where cost_date = '%"+s+"%' ";
    //        database.execSQL(sql);
    //        database.close();
            return database.query(FAMILY_BILL,null,"cost_date LIKE ?",new String[]{"%"+s+"%"},null,null,"COST_DATE ASC");
        }
        public void deleteAllData(){
            SQLiteDatabase database = getWritableDatabase();
            database.delete(FAMILY_BILL,null,null);
        }
    
    
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    
        }
    }

     我在团队中的任务是编写可视化显示数据。

  • 相关阅读:
    Datastage 调度相关 dsjob
    DropdownList内容树状展示 字段前空格不显示
    IE兼容低版本设置
    跑数速度慢,修改参数
    cognos samples 安装配置【转】
    在子窗口中操作父窗口(刷新)
    html长文本自动换行
    Asp.net禁止缓存
    【Range Lookup】 根据年龄 求年龄分段ID
    目标表已有对应数据则不插入
  • 原文地址:https://www.cnblogs.com/yangxionghao/p/12772262.html
Copyright © 2020-2023  润新知