-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();
Nirav Ranpara
  • 13,753
  • 3
  • 39
  • 54
SWE
  • 131
  • 2
  • 7
  • 20

2 Answers2

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))
Jyotman Singh
  • 10,792
  • 8
  • 39
  • 55
  • Thank you, it's ok for the if statement. – SWE Mar 17 '16 at 07:29
  • 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; } – SWE Mar 17 '16 at 07:34
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