我有一个名为 person 的表,有 3 列。它们是ID、NAME和PASSWORD。我需要添加一个名为AGE的新列。我尝试这种方式,但它对我不起作用请帮助我克服这个问题
public class Userdb {
public static final String KEY_ROWID = "Id";
public static final String KEY_NAME = "Person_name";
public static final String KEY_PASSWORD = "Person_password";
public static final String KEY_AGE = "Person_age";
private static final String DATABASE_NAME = "People_db_1";
private static final String DATABASE_TABLE = "people_table";
private static final int DATABASE_VERSION = 1;
private static class Dbhelper extends SQLiteOpenHelper {
public Dbhelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME
+ " TEXT NOT NULL, " + KEY_PASSWORD + " TEXT NOT NULL); ");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE);
db.execSQL("ALTER TABLE " + DATABASE_TABLE +" ADD COLUMN "+ KEY_AGE +" TEXT NOT NULL ; ");
onCreate(db);
}
}