Android的选择凭身份证SQLite中排? [英] Android Select row by Id in Sqlite?

查看:108
本文介绍了Android的选择凭身份证SQLite中排?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android的源码,由id指定行,并写了下面的code,但它不返回任何记录。我已经写了 getAllRecords()方法返回的所有记录数据库。

谁能解释的错误,我想提出?

 公共银行getBankById(INT bankId)
    {

        光标光标= NULL;
        银行BNK = NULL;
        光标= this.db.rawQuery(SELECT * FROM+ BanksTable.NAME +,其中+ BanksTable.COL_ID +=+ bankId,NULL);
         如果(光标!= NULL)
            {
             如果(cursor.moveToFirst())
                {
             INT的id = cursor.getInt(cursor.getColumnIndex(BanksTable.COL_ID));
             字符串名称= cursor.getString(cursor.getColumnIndex(BanksTable.COL_NAME));
             字符串URL = cursor.getString(cursor.getColumnIndex(BanksTable.COL_IMAGE_URL));
             byte []的图像= cursor.getBlob(cursor.getColumnIndex(BanksTable.COL_IMAGE));
             BNK =新银行();
             bnk.setId(ID);
             bnk.setImageURL(URL);
             bnk.setName(名称);
             bnk.setImageByteArray(图像);
                }
             cursor.close();
            }
        返回BNK;

    }
 

解决方案

我结束了这个问题,通过改变parametor来命名。 它的怪异,但我仍然不知道为什么它不工作。

我得到银行ID喜欢0,1,2,3,4可能是它没有在sqlite的允许或内部影响,但还是我不知道。

 光标= this.db.rawQuery(SELECT * FROM+ BanksTable.NAME +,其中+ BanksTable.COL_NAME +=+ bankName +',空);
 

I want to get a specific row by id in android sqlite and have written the following code, but it does not return any records. I have written a getAllRecords() method which returns all records from database.

Can anyone explain mistake I am making?

public Bank getBankById(int bankId)
    {

        Cursor cursor=null;
        Bank bnk = null;
        cursor =  this.db.rawQuery("select * from " + BanksTable.NAME + " where " + BanksTable.COL_ID + "=" + bankId  , null);
         if (cursor != null)
            {
             if (cursor.moveToFirst())
                {
             int id = cursor.getInt(cursor.getColumnIndex(BanksTable.COL_ID));
             String name = cursor.getString(cursor.getColumnIndex(BanksTable.COL_NAME));
             String url = cursor.getString(cursor.getColumnIndex(BanksTable.COL_IMAGE_URL));
             byte[] image = cursor.getBlob(cursor.getColumnIndex(BanksTable.COL_IMAGE));
             bnk=new Bank();
             bnk.setId(id);
             bnk.setImageURL(url);
             bnk.setName(name);
             bnk.setImageByteArray(image);
                }
             cursor.close();
            }
        return bnk;

    }

解决方案

i ended up this problem by changing parametor to name. its weird but i still dont know why it was not working.

i was getting bank id like 0,1,2,3,4 may be it is not allowed in sqlite or internally effecting it but still i am not sure.

cursor =  this.db.rawQuery("select * from " + BanksTable.NAME + " where " + BanksTable.COL_NAME + "='" + bankName + "'" , null);

这篇关于Android的选择凭身份证SQLite中排?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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