2017-03-07 10 views
0

嗨那裏,那些3「PE_ ..」我首先添加值創建和那些3「et .._ getText()。toString()..」獲取新的更改用戶。你明白我的觀點了嗎?還是我的應用程序停止,因爲我調用更新方法上分貝以下:SQLite數據庫 - 更新查詢

controller.update_pw(PE_Desc, PE_Pass, PE_Note, etDesc.getText().toString(), etPass.getText().toString(), etNote.getText().toString()); 

這是我的數據庫我的更新方法:

public void update_pw(String old_description, String old_password, String old_note, String new_description, String new_password, String new_note){ 
    this.getWritableDatabase().execSQL("UPDATE PASSWALL SET PW_DESC='"+new_description+"', PW_PASS='"+new_password+"', PW_NOTE='"+new_note+"' " + 
      "WHERE PW_DESC='"+old_description+"', PW_PASS='"+old_password+"', PW_NOTE='"+old_note+"'"); 

我想知道的之間用逗號「PW_DESC ='',PW_PASS ='',PW_NOTE =''哪裏......」,這是否正確?需要你幫助,感謝你的建議。謝謝!

回答

0

您在WHERE子句缺少
條件必須由運營商分隔。

編輯: 更新值的另一種方法。

ContentValues newValues = new ContentValues(); 
newValues.put("PW_DESC", new_description); 
newValues.put("PW_PASS", new_password); 
newValues.put("PW_NOTE", new_note); 
SQLiteDatabase db=getReadableDatabase(); 
db.update("PASSWALL", newValues, "PW_DESC= '" + old_description + "' AND "+"PW_PASS= '" +old_password+ "' AND "+ "PW_NOTE= '" + old_note+ "'", null); 
+0

Ohhhkkaayy。還有SET後的條件? – APX

+0

我編輯了我的答案。 –

+0

謝謝你。現在我知道了哈哈 – APX

0

試試這個,

 public void update_pw(String old_description, String old_password, String old_note, String new_description, String new_password, String new_note) { 

      SQLiteDatabase db = this.getWritableDatabase(); 
      String strSQL = "UPDATE PASSWALL SET PW_DESC='" + new_description + "', PW_PASS='" + new_password + "', PW_NOTE='" + new_note + "' WHERE PW_DESC='" + old_description + "' AND PW_PASS='" + old_password + "' AND PW_NOTE='" + old_note + "'"; 
      db.execSQL(strSQL); 
     } 
+0

。感謝你的努力 – APX