How to make AUTO_INCREMENT on Android SQLite database?

后端 未结 4 1565
无人共我
无人共我 2020-12-15 19:01

Hey I want to create a database with an AUTO_INCREMENT column. But I don\'t know how to parse the value in the method insert. I just don\'t know what to parse to an AUTO_INC

4条回答
  •  半阙折子戏
    2020-12-15 19:55

    You don't have to parse anything. If the column was created as AUTOINCREMENT, just pass the other values:

    db.execSQL("insert into "
            + TABLE_NAME
            + "(contact_id, contact_name, number_type, contact_number, duration, date, current_time, cont) "
            + "values( "+ cId + ", " + cName + ", " + numType + ", "
            + cNum + ", " + dur + ", " + date + ", " + currTime + ", ? )");
    

    By the way, it's always recommended to insert data using the Android's insert method:

    ContentValues values = new ContentValues();
    values.put("contact_id", cId);
    values.put("contact_name", cName);
    // etc.
    db.insert(TABLE_NAME, null, values);
    

提交回复
热议问题