如何从 Cursor 获取 Bool (Java SQLite)

How to get Bool from Cursor (Java SQLite)

例如,如果我做一个 table 比如

db.execSQL("create table myTable (" + "id integer primary key autoincrement," + "title text," + "isImportant numeric" + ");");

想要获得“头衔”,我想要

String result;
Cursor c...;
int titleIndex = c.getColumnIndex("title");
do
  ...
  result = c.getString(titleIndex);
  ...
while (c.moveToNext());

同c.getInt、c.getDoule等,但没有c.getBoolean。那么如何从 table?

中获取“isImportant”的值呢?

没有 getBoolean() 方法,因为 there is no Boolean data type in SQLite(尽管您可以将列定义为布尔值)。

如果您已将列中的值存储为 01,那么您可以像这样检索布尔值:

String result;
boolean isImportant;
Cursor c...;
int titleIndex = c.getColumnIndex("title");
do
    ...
    result = c.getString(titleIndex);
    isImportant = (c.getInt(isImportantIndex) == 1);
    ...
while (c.moveToNext());