我正在尝试在Android中的SQLite数据库中创建一个表。我把所有东西都搞定了,但它一直告诉我,我没有列“年龄”,当我清楚的时候!有人可以帮忙吗?
// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "contactsManager";
// Contacts table name
private static final String TABLE_CONTACTS = "contacts";
// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_PH_NO = "phone_number";
private static final String KEY_AGE = "age";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
+ KEY_PH_NO + " TEXT," + KEY_AGE + "TEXT" + ")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS titles");
onCreate(db);
}
答案 0 :(得分:6)
在您声明String
列的age
中添加一个空格:
...+ KEY_PH_NO + " TEXT," + KEY_AGE + " TEXT" + ")";
此外,执行此操作后,您将要卸载该应用程序,然后重新安装它以进行此修改(因此将再次调用onCreate
方法。)
答案 1 :(得分:0)
您需要在TEXT
之前的空格字符中添加以下代码:
KEY_AGE + "TEXT"