對不起,你打擾了所有人,但有時幫助是我必須要求的。我是Android開發新手,目前我正在頻道ProgrammingKnowledge的YouTube上跟隨教程,以便在youtube上創建android數據庫,但是,它僅適用於一個表格,而我需要在數據庫中有3個表格,並且無法獲取我的方式。任何幫助,將不勝感激。提前致謝!如何在Android工作室數據庫中創建多個表格
這是我目前擁有的代碼。
公共類DatabaseHelper擴展SQLiteOpenHelper {
//database name declaration
public static final String DATABASE_NAME = "museum.db";
public static final String TABLE_NAME = "exponent_table";
public static final String COL_1 = "ID";
public static final String COL_2 = "TITLE";
public static final String COL_3 = "STORY";
public static final String COL_4 = "AUTHOR";
public static final String COL_5 = "DATE";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
SQLiteDatabase db= this.getWritableDatabase(); //will create database and table, just for checking, will be replaced
}
@Override
public void onCreate(SQLiteDatabase db) {
//creating tables ???
db.execSQL("create table "+TABLE_NAME+" (ID INTEGER PRIMARY KEY AUTOINCREMENT, TITLE TEXT, STORY TEXT, AUTHOR TEXT, DATE STRING)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
}
}
我見過的鏈接類似的東西: Multi-table database SQLite android
但還是不明白。