Good day. I have an input field and a button that adds a row to the database table. Tell me how to implement the logic. I want to make a boolean method that makes a check "is there such a string in the database or not". I wrote the following code, but it seems to me that it is not correct
dbHelper = new DBHelper(getActivity()); db = dbHelper.getWritableDatabase(); String selection = "example"; Cursor c = db.query("filtertable", null, selection, null, null, null, null); while(c.moveToNext()){ String stringDb = c.getString(c.getColumnIndex("filtername")); if (stringDb.equals(selection)) { return false; } else return true; } c.close(); dbHelper.close();