SQLite的查询返回null
问题描述:
我所做的SQLite的查询返回null
我有一个充满了我的图像标识的数据库一个gridview。现在我设置了一个onItemClickListner与我得到的imageID - >这个作品!现在我想用这个imageID搜索我的数据库,但是它总是返回“null”,但这不应该是因为如果我的数据库完全用这些imageID填充。 表的结构是:RowID |来源| INFO 在信息存储我的图像标识的
问题
怎么办我要改变光标,我可以克服信息的条目。 到这里你会发现我的光标的代码:
代码:
//Es wird nach der ID des smiley gesucht.
public Cursor getSmiley(String info) throws SQLException {
Cursor mCursor =
this.mDb.query(true, DATABASE_TABLE, new String[] { INFO, SOURCE,
}, INFO + "=" + info, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
我如何获得图像标识回
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(SFilterConfigActivity.this, "" + position, Toast.LENGTH_SHORT).show();
//Hier wird herrausgefunden welche ID das Bild hat und in den jeweiligen String gespeichert
source = String.valueOf(v.getId());
Log.v("IMAGEID", source);
SmileyHelper.open();
Cursor c = SmileyHelper.getSmiley(source);
startManagingCursor(c);
if (c != null){
String size = String.valueOf(c.getCount());
Log.v("WhatsInC", size);
}
if (c.moveToFirst()) {
do {
text = c.getString(c.getColumnIndex(SmileyDBAdapter.SOURCE));
Log.v("WHATINTEXT", text);
smiley = c.getString(c.getColumnIndex(SmileyDBAdapter.INFO));
Log.v("WHATINSMILEY", smiley);
} while (c.moveToNext());
SmileyHelper.close();
其它信息:
- WhatIsInC,返回 “0”。
如果您需要更多的代码,只需告诉我 Thx为您的帮助提前! 问候 野生动物园
答
public Cursor getEmpByDept(String Dept)
{
SQLiteDatabase db=this.getReadableDatabase();
String [] columns=new String[]{"_id",colName,colAge,colDeptName};
Cursor c=db.query(viewEmps, columns, colDeptName+"=?",
new String[]{Dept}, null, null, null);
return c;
}
的db.query具有以下参数:
1.String Table Name: The name of the table to run the query against
2.String [ ] columns: The projection of the query, i.e., the columns to retrieve
3.String WHERE clause: where clause, if none pass null
4.String [ ] selection args: The parameters of the WHERE clause
5.String Group by: A string specifying group by clause
6.String Having: A string specifying HAVING clause
7.String Order By by: A string Order By by clause
所以,在您的查询,
this.mDb.query(DATABASE_TABLE, new String[] { INFO, SOURCE },INFO + " = '" + info + "'" , null, null, null, null, null);
或
this.mDb.query(DATABASE_TABLE,new String[] {INFO, SOURCE},INFO + " = ?",new String[]
{info},null, null, null, null);
我改变它,但它的仍为空......执行是不确定的.. :( – safari
执行是不确定的.. :( – safari
但比我必须删除光标权?因为这是无效的。 – safari