我正在开发一个应用程序,因为我必须更新一些列,我为更新查询编写语法,但它显示语法错误请告诉我我错误的位置
我的更新查询
public String updateEntry(UserDetailsDTO userDetails)
{
StringBuilder sb = new StringBuilder();
Cursor cur= myDB.rawQuery("UPDATE "+UserDBHandler.USER_TABLE+" SET
"+UserDBHandler.DOOR_NUMBER+" = '"+userDetails.getDoorNo()
+","+UserDBHandler.LANDMARK+" =
'"+userDetails.getLandMark()+","+UserDBHandler.STREET+" =
'"+userDetails.getStreet()+
","+UserDBHandler.CITY+" =
'"+userDetails.getCity()+","+UserDBHandler.STATE+" = '"+userDetails.getState()+"'
WHERE "+
UserDBHandler.USER_NAME+" = ?",new
String[]{userDetails.getUserName()});
if(cur.moveToFirst()){
UserDetailsDTO comb_off_job = new UserDetailsDTO();
comb_off_job.setDoorNo(cur.getString
(cur.getColumnIndexOrThrow(UserDBHandler.DOOR_NUMBER)));
comb_off_job.setLandMark(cur.getString
(cur.getColumnIndexOrThrow(UserDBHandler.LANDMARK)));
comb_off_job.setStreet(cur.getString
(cur.getColumnIndexOrThrow(UserDBHandler.STREET)));
comb_off_job.setCity(cur.getString
(cur.getColumnIndexOrThrow(UserDBHandler.CITY)));
comb_off_job.setState(cur.getString
(cur.getColumnIndexOrThrow(UserDBHandler.STATE)));
sb.append(comb_off_job);
}
return sb.toString();
}
在我的活动中
userDetailsdto.setDoorNo(doorNumber);
userDetailsdto.setLandMark(Landmark);
userDetailsdto.setStreet(Street);
userDetailsdto.setCity(City);
userDetailsdto.setState(State);
userDetailsdto.setUserName(uName);
userDetalidImpl.updateEntry(userDetailsdto);
答案 0 :(得分:2)
是的,你有语法错误,因为Manju Zi在查询中说缺少'。
Cursor cur= myDB.rawQuery("UPDATE "+UserDBHandler.USER_TABLE+" SET
"+UserDBHandler.DOOR_NUMBER+" = '"+userDetails.getDoorNo()
+","+UserDBHandler.LANDMARK+" =
'"+userDetails.getLandMark()+","+UserDBHandler.STREET+" =
'"+userDetails.getStreet()+
","+UserDBHandler.CITY+" =
'"+userDetails.getCity()+","+UserDBHandler.STATE+" = '"+userDetails.getState()+"'
WHERE "+
UserDBHandler.USER_NAME+" = ?",new
String[]{userDetails.getUserName()});
检查一下。 可以帮到你吗
Cursor cur= myDB.rawQuery("UPDATE "+UserDBHandler.USER_TABLE+" SET "
+UserDBHandler.DOOR_NUMBER+" = '"+userDetails.getDoorNo()+"'"
+","+UserDBHandler.LANDMARK+" = '"+userDetails.getLandMark()+"'"+","+UserDBHandler.STREET+" = '"+userDetails.getStreet()+"'"+
","+UserDBHandler.CITY+" = '"+userDetails.getCity()+"'"+","+UserDBHandler.STATE+" = '"+userDetails.getState()+"' WHERE "+
UserDBHandler.USER_NAME+" = ?",new
String[]{userDetails.getUserName()});
答案 1 :(得分:2)
检查此更新的代码:
Cursor cur= myDB.rawQuery("UPDATE " + UserDBHandler.USER_TABLE +
" SET" + UserDBHandler.DOOR_NUMBER + " = '" + userDetails.getDoorNo() + "' ,"
+ UserDBHandler.LANDMARK + " = '" + userDetails.getLandMark() + "' ,"
+ UserDBHandler.STREET + " = '" + userDetails.getStreet() + "' ,"
+ UserDBHandler.CITY + " = '" + userDetails.getCity() + "',"
+ UserDBHandler.STATE + " = '" + userDetails.getState() + "' WHERE "
+ UserDBHandler.USER_NAME + " = ?",new
String[]{userDetails.getUserName()});
PS:Amol Sawant 96 Kuli更快