SQLite如何使用游标获取字符串项 [英] Sqlite how to get string items using cursor

查看:115
本文介绍了SQLite如何使用游标获取字符串项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public Cursor getImages(long rowId) throws SQLException
    {
        Cursor mCursor =
                db.rawQuery("select * from Pictures WHERE id=" + rowId + ";", null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;


    }

表格列"id,图片,评论"

Table columns "id, pic, comment"

我想获取pic&的值对字符串数组进行注释.

I want to take values of pic & comment to string array.

我的代码是:

int i=0;
        Cursor c1 = db.getImages(memberId);     
        c1.moveToFirst();
        while(c1.isLast()){
            pictures[i]=c1.getString(1);
            comments[i]=c1.getString(2);
            i++;
        }

这不起作用.

推荐答案

您应该这样做:

c1.getString(cursor.getColumnIndex("pic"));

c1.getString(cursor.getColumnIndex("comment"));

这篇关于SQLite如何使用游标获取字符串项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆