0

I want to update one row based on multiple row value, After run the application getting error like = ( FATAL EXCEPTION: main android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: UPDATE Tablename SET sFollowed=?,Code=?,Name=? WHERE Vessel_Name= )

Here is my update method in MyDbhelper class

public boolean update_isFollowed(String strVesselName , String strVesselNotationNumber, String strIsFollowed) {
        SQLiteDatabase db1 = getReadableDatabase();

        ContentValues values=new ContentValues();
        values.put(COL_VesselName,strVesselName );
        values.put(COL_ClassCodeNumber , strVesselNotationNumber);
        values.put(COL_IsFollowedVessels, strIsFollowed);

       int id=db1.update(Table_VesselList,values,COL_ClassCodeNumber + "=" +strVesselNotationNumber +" and "+ COL_VesselName +"="+strVesselName,null);

        return id > 0;
    }
1
  • Check that strVesselName is not null. Commented Aug 3, 2015 at 11:51

2 Answers 2

1

Do something like this

In your activity

private UpdateDataInDB mUpdateDataInDb;
mUpdateDataInDb = new UpdateDataInDB(activity);

// call the update method with updated strings
mUpdateDataInDb.updateCommentDetails(_name, heading, comment);

In Database class

public void updateCommentDetails(String name, String updatedHeading,
        String updatedComment) {
    // TODO Auto-generated method stub
    mDatabase = mDatabase_handler.getReadableDatabase();
    ContentValues args = new ContentValues();
    args.put("Heading", updatedHeading);
    args.put("Comment", updatedComment);
    mDatabase.update("AddCommentTable", args,"Name" + "= ?", new String[]{ name });
    args.clear();
}
Sign up to request clarification or add additional context in comments.

Comments

0

Use proper where condition string with values as argument. like:

String where = COL_ClassCodeNumber+"=? AND "+COL_VesselName="?";
String[] whereArgs = new String[] {String.valueOf(strVesselNotationNumber),
                                   String.valueOf(strVesselName)};
int id=db1.update(Table_VesselList,values,where,whereArgs);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.