Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

I've been trying to update a specific row for a while now, and it seems that there are two ways to do this. From what I've read and tried, you can just use the:

execSQL(String sql)

 the method

or the:

update(String table, ContentValues values, String whereClause, String[] whereArgs) method.

(Let me know if this is incorrect as I am new to android and very new to SQL.)

So let me get to my actual code.

myDB.update(TableName, "(Field1, Field2, Field3)" + " VALUES ('Bob', 19, 'Male')", "where _id = 1", null);

I am trying to accomplish this:

Update Field1, Field2, and Field3 where the primary key (_id) is equal to 1.

Eclipse gives me a red line right underneath the word "update" and gives me this explanation:

The method update(String, ContentValues, String, String[]) in the type SQLiteDatabase is not applicable for the arguments (String, String, String, null)

I'm guessing I'm not assigning the ContentValues correctly. Can anyone point me in the right direction?

1 Answer

0 votes
by (40.7k points)

Try making the ContentValues object like this:

ContentValues cv = new ContentValues();

cv.put("Field1","Bob"); //These Fields will be your String values of actual column names



After that you can use the update method like this:

myDB.update(TableName, cv, "_id="+id, null)

Related questions

0 votes
1 answer
asked Jul 29, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Nov 20, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories