我正在尝试在 sqlite android 开发中创建表。我的问题是,只创建了一张表,但没有创建另一张表。
这是我创建它们的方法。
@Override
public void onCreate(SQLiteDatabase db)
{
try
{
db.execSQL(DATABASE_CREATE);
db.execSQL(DATABASE_CREATE2);
}
catch(SQLException e)
{
e.printStackTrace();
}
}
变量:
private static final String DATABASE_CREATE =
"create table if not exists profiles (_id integer primary key autoincrement, "
+ "firstname VARCHAR not null, age VARCHAR not null, "
+ "heightft VARCHAR not null, heightin VARCHAR not null, weight VARCHAR not null, duration VARCHAR not null, bmi VARCHAR not null);";
private static final String DATABASE_CREATE2 =
"create table if not exists routines (_id integer primary key autoincrement, "
+ "weightclass VARCHAR not null, musclegroup VARCHAR not null, "
+ "exercise VARCHAR not null, numberofsets VARCHAR not null, numeberofrepitition VARCHAR not null, day VARCHAR not null);";
关于问题是什么的任何想法?谢谢!
更新:
private static final String DATABASE_NAME = "fgtDB";
private static final String DATABASE_TABLE = "profiles";
private static final String DATABASE_TABLE2 = "routines";
private static final int DATABASE_VERSION = 2;
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
try
{
db.execSQL(DATABASE_CREATE);
db.execSQL(DATABASE_CREATE2);
}
catch(SQLException e)
{
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS profiles");
onCreate(db);
}
}