返回从sqlite的搜索到的数据 [英] Return the searched data from sqlite

查看:274
本文介绍了返回从sqlite的搜索到的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用字符串,和放大器来搜索sqlite的一个项目;试图返回包含该行中的描述。项目被存储在一个名为文章与列名 AS_name ,&安培表;说明列名称 Desc_art 对此我无法返回。

I am trying to search an item in sqlite by using String, & trying to return description contained in that row. items are stored in the table named Articles with column name AS_name, & the description column name is Desc_art which I am unable to return.

这是我的code:

public String searchData(String item) {
    String strvalue = null;
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cur = null;
    String strquery = "select * from Articles where AS_name = "+item;
    cur = db.rawQuery(strquery,null); 
    if(cur! = null&&cur.moveToFirst()) {
        do {
            strvalue = cur.getString(0);
        } while(cur.moveToNext());
    }
    return strvalue;  
}

这是我收到的错误:

我很困惑,请帮助..

I am confused please help..

推荐答案

在您的查询项目是字符串,因此更改

In your query item is string,So change

String strquery="select * from Articles where AS_name= "+item;

String strquery="select * from Articles where AS_name='" + item + "'";

或者这

Cursor cur=null;
cur = db.query("Articles", null, "AS_name" + "=?",
            new String[] { item }, null, null, null, null);

而不是

Cursor cur=null;
String strquery="select * from Articles where AS_name= "+item;
cur=db.rawQuery(strquery,null); 

和变化

strvalue=cur.getString(0);

strvalue=cur.getString(cur.getColumnIndex("Desc_art"));

这篇关于返回从sqlite的搜索到的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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