package com.example.picture_share; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.widget.Toast; import androidx.annotation.Nullable; public class Database extends SQLiteOpenHelper { private static final String dbname="mydb"; private Context mContext; public Database(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) { super(context, name, factory, version); mContext=context; } public Database(Context context){ super(context,"mydb",null,1); mContext=context; } @Override public void onCreate(SQLiteDatabase db) { //创建一个用户表,包括所有用户,里面有id,密码,用户名和头像 db.execSQL("create table if not exists users"+ "(id text primary key," + "password text not null,"+ "name text ,"+ "touxiang blob)"); //创建一个图片表,存储图片,图片的id,详细信息,以及发布的用户id和图片 db.execSQL("create table if not exists picturestable"+ "(idnum text ,"+ "details text,"+ "usrerid text,"+ "pictures blob)"); //创建一个收藏点赞表,存放图片id,个人账号 db.execSQL("create table if not exists personlikes"+ "(idnum text ,"+ "usrerid text)"); Toast.makeText(mContext,"数据库创建成功", Toast.LENGTH_SHORT).show(); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }