sqlite表中没有插入第四列?

时间:2019-07-16 10:14:35

标签: android android-sqlite sql-insert

我已经在SQLite表中添加了3列,并且工作正常。但是当我添加第四列时,它不起作用。我想这可能与查询有关。

private  static String key_id="id";
private  static String key_name="name";
private  static String key_email="email";
private  static String key_phone="phone";
private  static String key_table="user_table";

      public void onCreate(SQLiteDatabase db) {


     /**please add the fourth column which will be key_mobile I already 
     tried but still not working****/ 

     db.execSQL("CREATE TABLE " + key_table + " (" + key_id + " INTEGER 
     PRIMARY KEY AUTOINCREMENT, " + key_name + " TEXT NOT NULL, " + 
     key_email + " TEXT NOT NULL, " + key_phone + " TEXT NOT NULL);");
     }

     public long insertCustomer(Customer customer)
     {
      SQLiteDatabase sqlite= this.getWritableDatabase();
      ContentValues values = new ContentValues();
      values.put(key_id,customer.getId());
      values.put(key_name,customer.getName());
      values.put(key_email,customer.getEmail());
      values.put(key_phone,customer.getPhone());
      long row = sqlite.insert(key_table,null,values);
      sqlite.close();
      return row;
     }

当我删除(key_phone +“ TEXT NOT NULL”时,它可以工作,但是我需要第四列。insert方法返回-1而不是当前行ID。

0 个答案:

没有答案