Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite update query showing error

I have a following table:

sdb.execSQL("create table if not exists userprofile (id integer primary key, profilename text, user text);");

I want to update profilename field in Android SQLite.

So I used the following code:

ContentValues cv= new ContentValues();
cv.put("user",et4.getText().toString());
String admin="user1";
sdb.update("userprofile", cv, "profilename = " + admin, null);

The table have profilename value as user1. But when I execute this I am getting

03-14 09:12:55.851: E/SQLiteLog(26616): (1) no such column: user1

Please help me to resolve the problem.

Thanks in advance.

like image 663
krishna kumar Avatar asked Sep 13 '26 07:09

krishna kumar


1 Answers

Try to do it like this:

sdb.update("userprofile", cv, "profilename = ?", new String[] {"user1"});

I recommend this approach. Usage of placeholders solve problems like this. Your approach doesn't work because you are missing single quotes.

like image 120
Simon Dorociak Avatar answered Sep 14 '26 19:09

Simon Dorociak