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();
    
  • 相关阅读:
    git本地仓库基本使用(Repository)
    归途
    PowerDesigner逆向工程导入MYSQL数据库总结(转载)
    协程
    os.path.split 和 os.path.splitext
    转载)Linux平台下安装 python 模块包
    Java之map使用方法
    Java学习(JDBC java连接数据库)
    python -- 找出列表list中的重复元素
    JAVA打印变量类型
  • 原文地址:https://www.cnblogs.com/Mr-quin/p/8583741.html
Copyright © 2011-2022 走看看