数据库查询的问题,有个参数不会用?

中才德创 2016-03-02 05:56:11
query函数的columns,如果为null,查询出来非常顺!
可一旦设置了我只需要的一列,查询就报错了:
Couldn't read row 0, col 3 from CursorWindow. Make sure the Cursor is initialized correctly before
是不是语法错了?

/**
* 查询数据集
* @param id, 自增的那个id
* @return 数据内容
*/
public String queryId(int id) {
synchronized (OBJ_LOCK) {
String content = "";
//???
String[] columns = {"content"};
String selection = "id=?";
String[] whereArgs = {id+""};

SQLiteDatabase db = null;
Cursor cursor = null;
db = getWritableDatabase();
try {
cursor = db.query(s_tableName, columns, selection, whereArgs, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
content = cursor.getString(3);
String datatime = cursor.getString(4);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
close();
}

return content;
}
}
...全文
95 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
中才德创 2016-04-20
  • 打赏
  • 举报
回复
这是函数的说明:

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧