Essential Android SQLite using ContentValues edit forum

Inserting and updating rows in a SQLite database

First, you need to open your SQLite database, which can be done as follows:

SQLiteDatabase myDataBase; 
String mPath = dbhelper.DATABASE_PATH + dbhelper.DATABASE_NAME;
myDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.OPEN_READWRITE);

After opening the database, you can easily insert or update rows by using the ContentValues class. The following examples assume that a first name is given by str_edtfname and a last nameby str_edtlname. You also need to replace table_name by the name of your table that you want to modify.

Inserting data

ContentValues values = new ContentValues();
values.put("First_Name", str_edtfname);
values.put("Last_Name", str_edtlname);
myDataBase.insert("table_name", null, values);

Updating data

ContentValues values = new ContentValues();
values.put("First_Name", str_edtfname);
values.put("Last_Name", str_edtlname);
myDataBase.update("table_name", values, "id" + " = ?", new String[] {id});

Table Of Contents
39 ACRA
64 Menu
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
251 SQLite using ContentValues
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close