Using Execsql For Insert Operation In Android Sqlite
Solution 1:
You can use it, it is just not recommended because you won't receive any information that might be generated by the DB. The methods you are supposed to use return codes/cursors/other info to let you know what happened so you can deal with them if there is a problem.
The key is this line in the execSQL
docs:
It has no means toreturn any data (such as the number of affected rows). Instead, you're encouraged to use insert...
The important word there is "encouraged". You can use execSQL
for any SQL command, but you get no feedback on the process, which makes it rather dangerous to use for something where you should get feedback (unless you don't care than an insert failed, or only 2 of 5 records got updated).
Solution 2:
insert operation can be done in the Following way
SQLiteDatabasedb=this.getWritableDatabase();
ContentValuesvalues=newContentValues();
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
Post a Comment for "Using Execsql For Insert Operation In Android Sqlite"