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();
    
  • 相关阅读:
    安装提示设备为允许启用的解决办法
    xargs命令
    MariaDB链接超时优化
    灵活QinQ配置
    批量删除.pyo后缀的文件
    netcat的使用
    xxe(xml外部实体注入)
    渗透测试前:信息收集
    windows文件命名特性利用漏洞
    ssrf(Server-Side Request Forgery)
  • 原文地址:https://www.cnblogs.com/Mr-quin/p/8583741.html
Copyright © 2011-2022 走看看