我正在尝试从数据库表中检索仅为非空
的数据,但是IS NOT NULL
子句似乎无效。 空字段也被显示。
我想要检索那些没有null
值的信息,但是使用IS NOT NULL
语句好像不起作用,会把有空值的字段也一并显示出来。
String sql = "SELECT _id, nome_sotto FROM Categorie
WHERE nome_categoria = '"+i.getStringExtra("categoria")+"'
AND nome_sotto IS NOT NULL ORDER BY nome_sotto ASC";
private void list() {
SQLiteDatabase db = mHelper.getReadableDatabase();
final List<Dettaglio> dettagli = new ArrayList<Dettaglio>();
String sql = "SELECT _id, nome_sotto FROM Categorie
WHERE nome_categoria = '"+i.getStringExtra("categoria")+"'
AND nome_sotto IS NOT NULL ORDER BY nome_sotto ASC";
Cursor c = db.rawQuery(sql, null);
while (c.moveToNext()){
Dettaglio d = new Dettaglio();
d.id = c.getString(0);
d.sottocat = c.getString(1);
dettagli.add(d);
}
c.close();
db.close();
ListAdapter adapter....
}
_id
字段是字符串吗?通常在数据库查询中它是long
类型,而 CursorAdapter 期望它是long
类型。 - Graham Borland