0

I have a simple question : I'm new to sql so i have this question :

The below method works if names is a number. How to write this query if names is a string?

ourDatabase.update(DATABASE_TABLE, cv , KEY_NAME + "=" + names, null);

1 Answer 1

2

String literals in SQL are quoted in 'single quotes'.

Though it's preferable to use ? literal placeholders and bind arguments here, e.g.

ourDatabase.update(DATABASE_TABLE, cv, KEY_NAME + "=?", new String[]{names} );
Sign up to request clarification or add additional context in comments.

5 Comments

I copied and pasted your code but it gave me an error ! Invalid syntax expression on "?"
@user3496326, you should change KEY_NAME + "=" + ? to KEY_NAME + "=?"
Yes there was a missing terminating " - added by @Ȃŵåiṩĸîŋg edit.
@laalto Thanks a lot mate :) been searching this simple thing for an hour :)
Thanks to @laalto for adding this answer and good to hear that is working

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.