我的Android应用程序中有更新查询。但它不能正常工作。单击更新应用程序的按钮时停止工作。代码如下 -
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();
}
}
}
});
答案 0 :(得分:1)
将以下查询替换为现有查询:
stdDB.execSQL("Update student set name = '"+get_new_name + "' where id = "+get_std_for_update);
在名称和空格周围标记单引号。
希望这有帮助。
答案 1 :(得分:0)
试试
stdDB.execSQL("Update student set name = '"+get_new_name + "' where id = "+get_std_for_update);
或
stdDB.execSQL("Update student set name = \""+get_new_name + "\" where id = "+get_std_for_update);
请注意我添加了引号,并在where子句后添加了空格。