I have worked on sample application for insert the data into SqliteDb and try for get the first row first column value from the database(first cell value).
I have implemented code for store the data into data base as follows:
private SQLiteDatabase sqLiteDatabase;
//create table MY_DATABASE (ID integer primary key, Content text not null);
private static final String SCRIPT_CREATE_DATABASE =
"create table " + MYDATABASE_TABLE + " ("
+ KEY_ID + " integer primary key autoincrement, "
+ KEY_CONTENT1 + " text not null, "
+ KEY_CONTENT2 + " text not null);";
to insert the data
public long insert(String content1, String content2){
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_CONTENT1, content1);
contentValues.put(KEY_CONTENT2, content2);
return sqLiteDatabase.insert(MYDATABASE_TABLE, null, contentValues);
}
from the above code i can able to save the data in db but how can i get the last inserted KEY_CONTENT1 value from the same DB?
please any body help me
The return value of
insert()is the row id you just created. Use that to query for theKEY_CONTENT1. This would be the saves way (much more secure than a temporary variable to store the value ofKEY_CONTENT1)