I am storing data into SQLite table, and if data already exist(s) then updating it, and i am able to do that but whenever i update my existing record it saves another copy of that record...
Database:
public long InsertData(String strImageName, String strTitle) {
try {
SQLiteDatabase db;
db = this.getWritableDatabase();
ContentValues Val = new ContentValues();
Val.put("ImageName", strImageName);
Val.put("Title", strTitle);
long rows = db.insert(TABLE_MEMBER, null, Val);
db.close();
return rows;
} catch (Exception e) {
return -1;
}
}
public long UpdateData(String strImageName, String strTitle) {
try {
SQLiteDatabase db;
db = this.getWritableDatabase();
ContentValues Val = new ContentValues();
Val.put("Title", strTitle);
long rows = db.update(TABLE_MEMBER, Val, "ImageName=?",
new String[] { String.valueOf(strImageName) });
db.close();
return rows;
} catch (Exception e) {
return -1;
}
}
public boolean Exists(String strImageName) {
SQLiteDatabase db;
db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("select 1 from Data where ImageName= ?",
new String[] { strImageName });
boolean exists = (cursor.getCount() > 0);
cursor.close();
return exists;
}
InsertDataActivity.java:-
public boolean saveData()
{
long storeData = databaseDataHelper.InsertData(
txtImageName.getText().toString(),
editTitle.getText().toString()
);
if(storeData <= 0)
{
}
else
storeData = databaseDataHelper.UpdateData(
txtImageName.getText().toString(),
editTitle.getText().toString()
);
return true;
}
And one more thing, whenever i am creating database also getting .journal ... why ?
Aucun commentaire:
Enregistrer un commentaire