有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安卓如何从游标获取Bool(Java SQLite)

举个例子,如果我做一张像

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。那么,如何从该表中获得“isImportant”的值呢


共 (1) 个答案

  1. # 1 楼答案

    没有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());