Android | Sqlite3

Android 数据库创建及使用:

创建:

 

package he3.sd.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Created by asd25 on 2018/6/11 0011.
 */

public class UserDatabaseHelper extends SQLiteOpenHelper {


    private Context context;

    private String TAG = "数据库|DEBUG >>>:";

    public static final String CREATE_USER = "create table User("
            +"id integer primary key autoincrement,"
            +"sessionId text,"
            +"companyList text,"
            +"isActivate integer)";

    public UserDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,int version) {
        super(context,name,factory,version);
        this.context = context;
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(CREATE_USER);
        Log.d(TAG, "onCreate: "+"用户表创建");
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        sqLiteDatabase.execSQL("drop table if exists User");
        onCreate(sqLiteDatabase);
    }
}

 

 

 

在构造方法中有四个参数:

    context : 全局上下文

    name : 数据库名

    CursorFactory : 返回自定义游标

    version : 版本号,发生改变后执行 OnUpgrade 方法

 

Adb Shell :

    配置环境变量 : Path : D:\AndroidSdk\platform-tools
    cd : data\data\项目名\database\

    sqlite3 数据库名称

    .table查看表

 

posted @ 2018-06-20 15:51  杨超杰  阅读(186)  评论(0编辑  收藏  举报