这是我创建数据库表的代码
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_CTRL_TYPE + " TEXT,"
+ KEY_USER_NAME + " TEXT,"+ KEY_PASSWORD + " TEXT "
+ ")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
这是用于添加联系人
void addContact(Accounts accounts) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, accounts.getName()); // Contact Name
values.put(KEY_PH_NO, accounts.getPhoneNumber()); // Contact Phone
values.put(KEY_CTRL_TYPE, accounts.getControlType()); //
values.put(KEY_USER_NAME, accounts.getUserName()); //
values.put(KEY_PASSWORD, accounts.getPassword()); //
// Inserting Row
db.insert(TABLE_CONTACTS, null, values);
db.close(); // Closing database connection
}
我在访问时收到此错误addContact
db.addContact(new Accounts(siteName,siteNum,ctype,username,pass));
29206-29206/com.atrolabe.tcpremote1 E/SQLiteDatabase﹕ Error inserting control_type=SHAULA 720 user_name=wetyu phone_number=123455566 password=fhhchhjh name=test
android.database.sqlite.SQLiteException: table accounts has no column named control_type (code 1): , while compiling: INSERT INTO accounts(control_type,user_name,phone_number,password,name) VALUES (?,?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
logcat 在 addcontact 中指向这一行
db.insert(TABLE_CONTACTS, null, values);