Update function in android SQLite not working

In my application, I need to add and edit data to a SQLite database. When I do a function function update, the application does not give any errors, but my database will not be updated. Here is my update function. I have been searching the Internet for two days, but could not do it. Please help me.

public long updateEvent(String id, String title, String description, String reminder, String alarm, Date date) { try { int rowid = Integer.parseInt(id); Log.i("com.eventmanager", "insert Event"); formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String datestring = formatter.format(date); ContentValues cv = new ContentValues(); cv.put(KEY_TITLE, title); cv.put(KEY_DESCRIPTION, description); cv.put(KEY_REMINDER, reminder); cv.put(KEY_ALARM, alarm); cv.put(KEY_DATE, datestring); myDB.beginTransaction(); Log.i("com.eventmanager","SQL UPDATE "); myDB.update(DATABASE_TABLE, cv, KEY_ROWID + "=" + rowid, null); myDB.setTransactionSuccessful(); myDB.endTransaction(); } catch (Exception e) { e.printStackTrace(); } return 1; } 

Thanks in advance!

+4
source share
2 answers

There may be a problem in the update statement, try:

  long i = myDB.update(DATABASE_TABLE, cv, KEY_ROWID + "=?", new String[]{rowid}); if(i>0) return 1; // 1 for successful else return 0; // 0 for unsuccessful 

And yes, go through the publicly available int update (String values, ContentValues, String whereClause, String [] whereArgs) .

+7
source

Your function returns 1; which is not normal ... it should return ContentValues ​​cv

 return db.update(DATABASE_TABLE, cv, KEY_ROWID+"="+rowId, null) 
0
source

Source: https://habr.com/ru/post/1381093/


All Articles