mehmet
mehmet

Reputation: 1588

android update database error

Well I am trying to update a value in database false to true;

this is my code

public void updatecheck( int id){
     mDb = mDbHelper.getWritableDatabase();

       ContentValues newValues = new ContentValues();
       newValues.put("check", true);
       mDb.update(channel, newValues, "id"+" = ?", new String [] {String.valueOf(id)}); 

}

But I am taking this error,

02-28 15:15:37.515: E/AndroidRuntime(5539): android.database.sqlite.SQLiteException: near "check": syntax error (code 1): , while compiling: UPDATE Genelkultur2012 SET check=? WHERE id = ?

SOLVED:

new codes

 ContentValues newValues = new ContentValues();
         newValues.put("tamam", true);
         mDb.update(channel, newValues, "id"+" = ?", new String [] {String.valueOf(id)}); 

Upvotes: 0

Views: 85

Answers (2)

laalto
laalto

Reputation: 152817

CHECK is a reserved keyword in SQL. Either rename the column or quote it in backticks.

Upvotes: 3

Saket
Saket

Reputation: 3076

newValues.put("check", true);

You're trying to store true, a Boolean data type, which is not supported by SQLite. You'll instead have to store them in one of the following types:

  1. NULL. The value is a NULL value.
  2. INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
  3. REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number.
  4. TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).
  5. BLOB. The value is a blob of data, stored exactly as it was input.

I'd suggest to store Boolean members as 0 or 1. More info here: http://www.sqlite.org/datatype3.html

Upvotes: 1

Related Questions