Using execSQL for INSERT operation in Android SQLite

前端 未结 3 834
天命终不由人
天命终不由人 2020-12-11 10:40

From the documentation and this post I know execSQL() executes a single SQL statement that is not a SELECT or any other SQL statement that return

3条回答
  •  星月不相逢
    2020-12-11 10:49

    insert operation can be done in the Following way

     SQLiteDatabase db = this.getWritableDatabase();
    
        ContentValues values = new ContentValues();
        values.put(KEY_NAME, contact.getName()); // Contact Name
        values.put(KEY_PH_NO, contact.getPhoneNumber()); // Contact Phone
    
        // Inserting Row
        db.insert(TABLE_CONTACTS, null, values);
        //2nd argument is String containing nullColumnHack
        db.close(); // Closing database connection
    

    for more information refer the link with code http://www.blazin.in/2016/02/understanding-sqlite-database-in-android.html

提交回复
热议问题