Java – How to check if the value already exists in the android sqlite database?

How to check if the value already exists in the android sqlite database?… here is a solution to the problem.

How to check if the value already exists in the android sqlite database?

I have an app where users can enter names and other details for specific dates. I need to check if the value/name the user is trying to add already exists in the database column name. I have this code, but this doesn’t work because it only selects a value. Thanks

Cursor c = dbe.rawQuery("SELECT name FROM tbl_user WHERE meeting_date LIKE'" + mydate + "'", null);

if ((c.getString(3)).equals(editTextName.getText().toString()))

{
 do something
}

Solution

If you just check if there is a value in the field, the easiest way is to use the appropriate filter for the selection count.

Something like that

SELECT count(*)
FROM tbl_user
WHERE meeting_date LIKE ' + my_date'
AND name = ' + editTextName.getText() + '

This will allow you to easily and quickly determine whether these values exist in your table.

If you need to check multiple tables, you must join between them and write filters accordingly.

If it happens that you don’t have a good grasp of SQL.
This site is a great place to start:
W3Schools SQL Tutorial

Hope this helps you.

Related Problems and Solutions