I have a update query in my android application. But its not working properly. When clicking the button for updating the application stops working. The code is as follows-
update.setOnClickListener(new OnClickListener (){ @Override public void onClick(View v) { // TODO Auto-generated method stub String feched_name = show_name.getText().toString(); String get_std_for_update=id_search.getText().toString(); String get_new_name = id_update.getText().toString(); if(feched_name.matches("")){ Toast.makeText(getApplicationContext(), "No Student selected", Toast.LENGTH_LONG).show(); } else { if(get_new_name.matches("")){ Toast.makeText(getApplicationContext(), "New Name is empty", Toast.LENGTH_LONG).show(); } else{ stdDB.execSQL("Update student set name = "+get_new_name + "where id = "+get_std_for_update); Toast.makeText(getApplicationContext(), "Student's name has been updated", Toast.LENGTH_LONG).show(); } } } });2 Answers2
Replace the query below with the existing one :
stdDB.execSQL("Update student set name = '"+get_new_name + "' where id = "+get_std_for_update);Mark the single quote around the name and the space.
Hope this helps.
Sign up to request clarification or add additional context in comments.
2 Comments
Muntashir Are Rahi
Thats it. I forgot to add single quotes. Its working now. Thank you.
Shraddha
You should accept the answer if it was helpful to you, it will help others in future.
Try
stdDB.execSQL("Update student set name = '"+get_new_name + "' where id = "+get_std_for_update);or
stdDB.execSQL("Update student set name = \""+get_new_name + "\" where id = "+get_std_for_update);Please note I added quotes and also I added a space after your where clause.
Comments
Explore related questions
See similar questions with these tags.

