SQLite Exception: no such column in Android SQLite Exception: no such column in Android sqlite sqlite

SQLite Exception: no such column in Android


The error isn't saying that a value of "jo_2" is missing in the table, but that a column named jo_2 is missing. It sounds like you have some malformed SQL somewhere.

If this is your actual SQL (from the error):

UPDATE info SET name=?,number=? WHERE id =jo_2

Then you need some quotes around the jo_2 part:

UPDATE info SET name=?,number=? WHERE id = 'jo_2'

Without them, SQLite is comparing the column id to the column jo_2, which doesn't exist.

To fix this, you can change this line in your code:

return db.update(table_name, content, "id = '" + ID + "'", null);                        // add quotes here  ^      and ^

EDIT: Falmarri's answer shows a safer way to fix your code to avoid the error.


You're opening yourself up to SQL injection. Use the built in where clause parameter inserting.

public int update (String table, ContentValues values, String whereClause, String[] whereArgs)

So you want

return db.update(table_name, content, "id = ?", new String[] {"jo_2"});


I ran into this trouble what you can is this

 String originalYearString = uri.getLastPathSegment();            where= TableName.COL_YEAR_NAME+" = "+"'"+originalYearString+"'";//placing values of the column to be updated in '' is important or else it detects it as a single table column             if(!TextUtils.isEmpty(selection)){                where+=" AND "+selection;            }            rowUpdated=database.update(TABLE_NAME,values,where,selectionArgs);            break;