Search code examples
androidsql-updateandroid-sqlite

Multiple columns in where clause giving syntax error


I am facing a problem in updating a table with multiple columns in where clause of the db.update in sqlite.

Below is what I have tried but not accepting and showing syntax error.

db.getWritableDatabase().update(tablename, update((buy+dupbuy)), (column2+"=? and"+ column3+"=?"),(new String[] {getdate}+" and"+new String[] {stockname}));

In above query

  1. First parameter is tablename to be updated.
  2. second parameter is value to be updated which will point to another class update method where I wrote content values for updating the table
  3. Major one third part is parameters I need to pass in where clause.

but giving syntax error

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

How can I declare multiple columns in where clause?


Solution

  • Try changing

    db.getWritableDatabase().update(tablename, update((buy+dupbuy)), (column2+"=? and"+ column3+"=?"),(new String[] {getdate}+" and"+new String[] {stockname}));
    

    to

    db.getWritableDatabase().update(tablename, update((buy+dupbuy)), (column2+"=? and "+ column3+"=?"),(new String[] {getdate,stockname}));
    

    Add a space after the "and" in the WHERE clause and you need to pass a String[] and not String in the whereArgs parameter. Currently you are passing a String