我在使用 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/