Android 无法匹配存储在SQLite中的字符串

Android 无法匹配存储在SQLite中的字符串,android,database,android-sqlite,Android,Database,Android Sqlite,在我的应用程序的一部分中,我从移动设备获取日期,并将其作为字符串存储在SQLite数据库中 String currentDateString = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); MyDB.insertRow(currentDateString); 当我尝试从数据库中选择具有相同日期的行时,找不到任何匹配结果 同样在下面的代码中,我尝试获取表的特定单元格,我确信它与当前日期匹配。但没有对手 有什么想法吗 从手机获取日期

在我的应用程序的一部分中,我从移动设备获取日期,并将其作为字符串存储在SQLite数据库中

String currentDateString = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
MyDB.insertRow(currentDateString);
当我尝试从数据库中选择具有相同日期的行时,找不到任何匹配结果

同样在下面的代码中,我尝试获取表的特定单元格,我确信它与当前日期匹配。但没有对手

有什么想法吗

从手机获取日期并将其作为字符串插入

String currentDateString = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
MyDB.insertRow(currentDateString);
检查数据库中的日期是否等于移动日期

if (MyDB.getRow(21).getString(1).toString()==currentDateString)
Toast.makeText(getBaseContext(),"Match",Toast.LENGTH_SHORT).show();
在Java中,不能使用==运算符匹配字符串。您使用.equals方法,因为字符串不是基元类型

那么试试这个-

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

==运算符不匹配字符串,因为它是一个对象

试一试

如果您需要它,则不区分大小写


确保插入的日期格式与匹配的格式相同

谢谢,if语句可以。if语句可以。那么,我如何更新数据库公共布尔更新中的特定行where子句呢{String where=AttDate+=+AttDate\u Par;ContentValues newValues=new ContentValues;newValues.putSite,Site\u Par;newValues.putAttDate,AttDate\u Par;//将其插入数据库。返回db.updateDATABASE\u表,newValues,其中,null!=0;}
 MyDB.getRow(21).getString(1).toString().equalsIgnoreCase(currentDateString)