-3

In part of my application I get date from mobile and store it in SQLite Database as string.

when I try to select rows from database which have same date, can't find any match result.

Also as in below code, I tried to get specific cell of table which I'M sure it's match the current date. but no match.

is there any idea?

Get Date from mobile and insert it as string.

String currentDateString = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); MyDB.insertRow(currentDateString); 

Check if date from database equal mobile date.

if (MyDB.getRow(21).getString(1).toString()==currentDateString) Toast.makeText(getBaseContext(),"Match",Toast.LENGTH_SHORT).show(); 
0

2 Answers 2

1

You don't match Strings in Java using == operator. You use .equals() method as String is not a primitive type.

So try this -

if (MyDB.getRow(21).getString(1).toString().equals(currentDateString)) 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, it's ok for the if statement.
It's ok for the if statement. so how I can update specific row (where clause) in database public boolean updateRow( String Site_par,String AttDate_Par) { String where =AttDate + " = " + AttDate_Par; ContentValues newValues = new ContentValues(); newValues.put(Site,Site_par); newValues.put(AttDate, AttDate_Par); // Insert it into the database. return db.update(DATABASE_TABLE, newValues, where, null) != 0; }
1

Strings aren't matched by == operator because it is an object.

try

 MyDB.getRow(21).getString(1).toString().equals(currentDateString) 

and if you need it not case sensitive

 MyDB.getRow(21).getString(1).toString().equalsIgnoreCase(currentDateString) 

Also make sure that the inserted date format is the same that you match with

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.