0

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();                           }                    }            }           });
askedJul 18, 2013 at 6:22
Muntashir Are Rahi's user avatar

2 Answers2

1

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.

answeredJul 18, 2013 at 6:26
Shraddha's user avatar
Sign up to request clarification or add additional context in comments.

2 Comments

Thats it. I forgot to add single quotes. Its working now. Thank you.
You should accept the answer if it was helpful to you, it will help others in future.
0

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.

answeredJul 18, 2013 at 6:25
Martin Magakian's user avatar

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy 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.