It is required to update the rows of the table with the date corresponding to the condition. When calling a method for updating, an exception pops up.

android.database.sqlite.SQLiteException: near ".24": syntax error (code 1): , while compiling: UPDATE days_table SET expense = expense + 39.0 WHERE expdate = 2017.12.24 

What is the problem?

The code of the method in which the exception occurs

 @Override public void onClick(View v) { Intent intent = new Intent(); switch (v.getId()) { case R.id.etDate: DialogFragment dialogfragment = new DatePickerDialogClass(); dialogfragment.show(getFragmentManager(), "Date Picker Dialog"); break; case R.id.btnAdd: double dayExp; String day; String sCat ; String sComment; //Считывание данных из полей ввода dayExp = Double.parseDouble(etExp.getText().toString()); day = etDate.getText().toString(); sCat = tvSelCat.getText().toString(); sComment = etComm.getText().toString(); //Запись в БД boolean result = dbHelper.insertDayData(dayExp, sCat, day, sComment); if (result) { Toast.makeText(this, "Расход успешно добавлен", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Ошибка! Расход не добавлен", Toast.LENGTH_SHORT).show(); } //Обновляем таблицу с днями dbHelper.updateDaysData(dayExp, day); setResult(RESULT_OK, intent); finish(); break; } } 

Method code for record update

  public void updateDaysData(double dayExp, String day) { SQLiteDatabase db = this.getWritableDatabase(); db.execSQL("UPDATE " + DAYS_TABLE_NAME + " SET " + DAYS_COL_2 + " = " + DAYS_COL_2 + " + " + dayExp + " WHERE " + DAYS_COL_4 + " = " + day); } 
  • Enter your code, please. - Donald Rump
  • Added code above - Eugene
  • The date literal ( WHERE expdate = 2017.12.24 ) has an invalid format. - Akina
  • never substitute values ​​directly into text. Use prepared expressions and data binding. msdn.microsoft.com/ru-ru/library/… But if you still insist and want to create an application that will be exposed to sql injections, then just look at how dates are set in SQLite, probably in some quotes, in plain text One DB does not dates - Mike
  • Understood. As a delimiter in the date instead of a point should be a hyphen. - Eugene

0