由网友(暖了夏天蓝了海)分享简介:我想在Android的源码,由id指定行,并写了下面的code,但它不返回任何记录。我已经写了 getAllRecords()方法返回的所有记录数据库。谁能解释的错误,我想提出?公共银行getBankById(INT bankId){光标光标= NULL;银行BNK = NULL;光标= this.db.rawQuer...
我想在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);
相关推荐
最新文章