0

This works but i need to be able to change the value of the product_name

String query = "UPDATE UserTable SET _quantity=_quantity - 1 WHERE product_name ='Hammer'";
myDatabase.execSQL(query);

This does not work and I can't see why.

String test = "Hammer";
String query = "UPDATE UserTable SET _quantity=_quantity - 1 WHERE product_name ='%"+test+ "%'";
myDatabase.execSQL(query);
4
  • try to remove % % symbol on your query! Commented Oct 26, 2013 at 11:23
  • 1
    the % symbol is to match anything like what he wants %amme% would match hammer Commented Oct 26, 2013 at 11:24
  • its just for testing that I have the String test set to Hammer. Commented Oct 26, 2013 at 11:24
  • Removing the % symbol did the trick, Thank you!!! Commented Oct 26, 2013 at 11:26

3 Answers 3

1

Try this code

i think it will work

ContentValues data = new ContentValues();
data.put("Column Name", column_value);

i.e,

data.put("_quantity", 3);

myDatabase.update(TABLE_NAME ,data,"product_name = ?",new String[]{test});
Sign up to request clarification or add additional context in comments.

Comments

0

To match a pattern you should use the LIKE statement:

String test = "Hammer";
String query = "UPDATE UserTable SET _quantity=_quantity - 1 WHERE product_name LIKE '%"+test+ "%'";
myDatabase.execSQL(query);

Comments

0

You need to remove % symbols from your query. This symbols are used to match the strings values if you want to match anything like what he wants %mer% would match hammer

Try as below:

String query = "UPDATE UserTable SET _quantity=_quantity - 1 WHERE product_name ='"+test+ "'";

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.