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();   
                        }
                    }


            }

           });

2 Answers 2

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.

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.

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.