android - 如何从 Android 中的 SQLite 数据库中获取空值

标签 android sqlite targetnullvalue

我在使用 Android 从 SQLite 数据库获取空值时遇到问题。

我的数据库有 10 列。从第 1 列到第 8 列全部填入值。但是有几行第 9 列和第 10 列中的值为空或某个数字。

我要检查:

String selectQuery = "SELECT * FROM products WHERE barcodeId='" + id + "'";

Cursor myCursor = db.rawQuery(selectQuery, null);
if (myCursor.moveToFirst()) {

    //checking to see if there is something in column 9
    if(myCursor.getString(8) != null){
        // do soemthing
    }else {
        // if there is nothing do something
    }

    //checking to see if there is something in column 10
    if(myCursor.getString(9) != null){
        // do soemthing
    }else {
        // if there is nothing do something
    }
}

有人可以根据我在表格中第 9 列和第 10 列的示例提供工作代码吗?

也欢迎简要说明。 谢谢

最佳答案

我不知道 Cursor.getString() 是否会返回 null。文档没有说,它可能只是返回一个空字符串。你应该使用 Cursor.isNull()而是检查列中的空值。

关于android - 如何从 Android 中的 SQLite 数据库中获取空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21804254/

相关文章:

C#/WPF 文本框错误 : "Value ' ' cannot be converted", TargetNull 不工作

Android:如何将变量值存储到注册表?

android - 没有房间的分页图书馆

java - 我需要帮助在 android 查询生成器中选择不同的列值

mysql - SQL 查询以透视下表中的数据

ruby - 检测丢失的子!、排序!、 map !等

android - ICS 中的新 Android Calendar API 是否向后兼容?

android - 我在哪里可以获得 Android ICS 菜单按钮图标?

node.js - SequelizeDatabaseError : SQLITE_ERROR: no such table: Users