I am trying to set an integer and a string value in execSQL statement :
mydb.execSQL("UPDATE emptable set age=? where name=?",new int[] {emp_age},new String[] {emp_name});
where emp_age is an integer and emp_name is a String. But this is not working.How can i achieve this?
Sorry, but I’m not happy with the given answers, and I’ll explain why.
@hotveryspicy answer is not only ugly but also dangerous. I’ll remind you of the possibility of an SQL-injection, which can cost you your stored data.
The same is true for @john smith answer.
@user1318091 answer is incorrect for the same reason that makes all of these answers (including your given example-code) wrong. If you read the documentation, you’ll notice that it says:
on the first line. It also lists alternatives for the above mentioned operations:
If you choose to use the simple
update()-method, your query will look like this (untested!):Also check this question for the correct “where”-syntax: update sql database with ContentValues and the update-method