android - SQLite 奇怪的行为

标签 android android-sqlite

我想从表中检索特定单元格。我想要alarm_music(TEXT),其中我有存储在警报表中的警报的小时(INTEGER)和分钟(INTEGER)(在where子句中)。
触发查询的代码

mBhelperClass = new AlarmsDBhelperClass(this);
        db= mBhelperClass.getWritableDatabase();
        Cursor cursor = db.rawQuery("SELECT musicPath FROM alarms WHERE hours="+hour+" AND minutes="+min,null);
        Log.d("gaurnagSnooze",""+cursor.getCount());
        if (cursor.moveToFirst()) {
            songPath = cursor.getString(cursor.getColumnIndex(AlarmsDBhelperClass.MUSIC_PATH));
            Log.d("if executed! ","songpath initialized!");
        }
        cursor.close();

moveToFirst() 返回 FALSE 表示表中没有行。
但是当我开火SELECT musicPath FROM alarms moveToFirst() 返回 真的 .
这怎么可能?

最佳答案

问题: cursor.moveToFirst() 返回 表示不存在行。
解决方案:在表中插入行时,我使用了 24小时时钟格式日历的实例来自时间选择器并存储在表中。但是当我尝试使用小时作为 where 子句从数据库中检索值时,我使用了 12小时时钟格式日历的实例。这肯定不会产生任何输出,因此不会以 cursor 和 cursor.moveToFirst() 返回 FLASE 的形式返回行。

关于android - SQLite 奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60462058/

相关文章:

android编辑文本更改焦点背景

sqlite - java.lang.NullPointerException : Attempt to invoke virtual method on a null object reference to select sqlite 异常

android - 房间 : java. lang.IllegalStateException:现有数据库的迁移不正确

java - 如何用 Java 更新 SQlite 中特定列中的特定行?

java - 根据单选按钮值将值存储在 sqlite 数据库的多个表中

android - parse.com 是解析 JSON 吗? (安卓)

即使没有任何更改,Android 多模块 Gradle 构建也很慢

java - 无法解析方法“openFileOutput(java.lang.String,int)”

android - LocalBroadcastManager 和 Activity 生命周期

java - 如何在csv文件中存储引号,然后将该数据复制到android中的greendao