• 第18天android:《android从零开始》视频(2223)数据存储


    22.数据存储(1)

    22.1 存储方式:SQLite,文件,Shared Preferences,Content Providers,网络

    22.2 sqlite资料:http://www.sqlite.com.cn

    22.3 基本SQL命令 create,insert,select,delete,order by ,limit,group by ,having

    23.数据存储(2)

    23.1 一个DbHelper对象:

    //继承自SQLiteOpenHelper
    public class DBOpenHelper extends SQLiteOpenHelper {
    
        // 数据库的版本
        private static final int VERSION = 1;
        // 数据库的名字
        private static final String dbname = "data.db";
    
        /**
         * 
         * @param context
         *            to use to open or create the database
         * @param name
         *            of the database file, or null for an in-memory database
         * @param factory
         *            用来创建 cursor 对象, or null for the default
         * @param version
         *            number of the database (starting at 1); if the database is
         *            older, onUpgrade(SQLiteDatabase, int, int) will be used to
         *            upgrade the database; if the database is newer,
         *            onDowngrade(SQLiteDatabase, int, int) will be used to
         *            downgrade the database
         */
        public DBOpenHelper(Context context, String name, CursorFactory factory, int version) {
            super(context, name, factory, version);
        }
    
        // 安装后要在用户手机中创建表,在这里放一些表的创建,如果有表就不创建,
        @Override
        public void onCreate(SQLiteDatabase db) {
        }
    
        // 在数据库版本更新的时候调用。
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        }
    }

    23.2 getRandableDatabase() 获得只读数据库

    同样 getWritableDatabase() 可写不可读。

    23.3 db.execSql("insert into tt values('xx','xx','xx')",null)

    db.execSql("insert into tt values(?,?,?)", new Object[]{'xx','xx','xx'})

    23.4 Curosr的使用

    ind = cursor.getColumIndex("sid");//这个获取这个字段的index位置。

    cursor.getInt(ind);//获取这个。

  • 相关阅读:
    构造函数与其他方法的区别
    记录点复习题目和linux学习
    找点面试题目
    linux代码常用查询!!!!!!!!!!!!
    python复习
    明天面试今天赶紧准备下
    文都计算机考研课程
    是时候刷笔试题目了
    倒排索引
    总结算法课程
  • 原文地址:https://www.cnblogs.com/wanself/p/2798819.html
Copyright © 2020-2023  润新知