title: Update SQLite Database
body: <p>I have a SQLite database set up from this tutorial changing it around to my own project: <a href="http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/" rel="nofollow">http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/</a></p>
  
  <p>However the tutorial does not mention how to update a field.. I have tried this:</p>
  
  <pre><code>db = new NotesDatabaseHandler(ViewNoteActivity.this);
  ...
  db.updateNote(new Note(identifier, editTextTitle.getText().toString(), editTextContent.getText().toString(), "Updated on: " + printStandardDate()));
  </code></pre>
  
  <p>Although have had no luck.. I run the application and the note will not update.</p>
  
  <p>Note class:</p>
  
  <pre><code>package com.timmo.notes;
  
  class Note {
  
  //private variables
  private int _id;
  private String _title;
  private String _content;
  private String _metadata;
  
  // Empty constructor
  public Note() {
  
  }
  
  // constructor
  public Note(int id, String title, String content, String metadata) {
      this._id = id;
      this._title = title;
      this._content = content;
      this._metadata = metadata;
  }
  
  public int getID() {
      return this._id;
  }
  
  public void setID(int id) {
      this._id = id;
  }
  
  public String getTitle() {
      return this._title;
  }
  
  public void setTitle(String title) {
      this._title = title;
  }
  
  public String getContent() {
      return this._content;
  }
  
  public void setContent(String content) {
      this._content = content;
  }
  
  public String getMetadata() {
      return this._metadata;
  }
  
  public void setMetadata(String metadata) {
      this._metadata = metadata;
  }
  
  }
  </code></pre>
  
  <p>From NotesDatabaseHandler():</p>
  
  <pre><code>// Updating single note
  public int updateNote(Note note) {
      SQLiteDatabase db = this.getWritableDatabase();
  
      ContentValues values = new ContentValues();
      values.put(KEY_TITLE, note.getTitle());
      values.put(KEY_CONTENT, note.getContent());
      values.put(KEY_METADATA, note.getMetadata());
  
      // updating row
      int ret = db.update(TABLE_NOTES, values, KEY_ID + " = ?",
              new String[]{String.valueOf(note.getID())});
      db.close();
      return ret;
  }
  </code></pre>
  
  <p>Previously, I have deleted the note, then added it in again, but this adds it to the end of the database instead of in the same position.</p>
  
  <p>So, to the question, how do I properly update one of my notes (contacts) from the method I am using? Thanks</p>
  
  <p>Update:
  I've tried using a raw UPDATE:</p>
  
  <pre><code>public void updateNote(Note note) {
      SQLiteDatabase db = this.getWritableDatabase();
  
      String strSQL = "UPDATE "
              + TABLE_NOTES + " SET "
              + KEY_TITLE + "='" + note.getTitle() + "', "
              + KEY_CONTENT + "='" + note.getContent() + "', "
              + KEY_METADATA + "='" + note.getMetadata() + "'"
              + " WHERE " + KEY_ID + "='" + note.getID() + "'";
      Log.d("SQL: ", strSQL);
      db.execSQL(strSQL);
      db.close();
  }
  </code></pre>
  
  <p>Yet still nothing happens. My Log outputs:</p>
  
  <pre><code>UPDATE notes SET title='hello', content='there', metadata='Updated on: 09:48 AM - 08 Aug 2015' WHERE id='7'
  </code></pre>
  
  <p>I can't see what's wrong...</p>