zoukankan      html  css  js  c++  java
  • Android轻量数据库

    SQLite

    创建数据库

    final SQLiteDatabase db = openOrCreateDatabase("graphicsCard", Context.MODE_PRIVATE,null);
    String create = "create table if not exists graphicsCard(id integer primary key autoincrement,name text not null,price integer not null);";
    db.execSQL(create);
    
    id name price
    * * *

    增加数据

    final ContentValues in = new ContentValues();
    in.put("name", "GTX1080 ti");
    in.put("price", 8299);
    db.insert("graphicsCard", null, in);
    
    in.put("name", "GTX1080");
    in.put("price", 4799);
    db.insert("graphicsCard", null, in);
    
    id name price
    1 GTX1080 ti 8299
    2 GTX1080 4799

    int price = Integer.parseInt(et_search.getText()+"");
    String search = "select * from graphicsCard where price = "+price;
    Cursor cursor = db.rawQuery(search,null);
    String str = null;
    if(cursor.moveToNext()){
        str = cursor.getString(cursor.getColumnIndex("id"))+"  "
        +cursor.getString(cursor.getColumnIndex("name"))+"  "
        +cursor.getInt(cursor.getColumnIndex("price"));
      }
    cursor.close();
    

    关闭

    db.close();
    

    SharedPreferences

    创建

    SharedPreferences sp;
    sp = getSharedPreferences("save", Activity.MODE_PRIVATE);
    boolean isFirst = sp.getBoolean("save",true);
    

    SharedPreferences.Editor editor = sp.edit();
    isFirst = false;
    editor.putBoolean("save",isFirst);
    editor.commit();
    
  • 相关阅读:
    微信小程序 原生框架 (分享方法封装)
    JavaScript 正则表达式学习笔记
    JavaScript Date
    JavaScript String
    JavaScript Array
    前端开发缓存问题的解决方案
    参数验证
    html中的关于距离的总结大全
    Vuex的辅助函数mapState, mapActions, mapMutations用法
    Vue的内置组件transition
  • 原文地址:https://www.cnblogs.com/Mr-quin/p/8583741.html
Copyright © 2011-2022 走看看