10

我的想法很简单。我有一个包含三列的 SQLite 数据库:

  1. 行号
  2. 标题 => 文本
  3. 内容 => 文本

这是我的类中的一种方法dataBase

public Cursor fetchMessage(String tableNane, int id) {
    return myDataBase.rawQuery("SELECT rowid as _id, title FROM "+tableName
    +" WHERE rowid = "+id, null);
}

此方法将仅返回一行。

在我的活动中,我写道:

Cursor cursor = myDbHelper.fetchMessage(tableName, id);

现在,我想将内容字段的文本存储在字符串中。

如何才能做到这一点?

4

2 回答 2

27

用这个:

if (cursor.moveToFirst()) {
    str = cursor.getString(cursor.getColumnIndex("content"));
}
于 2011-07-10T12:00:34.057 回答
8

首先,您需要使用 - 方法将您从查询中获得的光标移动到第一行moveToFirst()

之后,您可以使用getString()or getInt()-methods 获取字段值。

于 2011-07-10T12:04:19.097 回答