SQLite 查询返回 null

发布于 2024-12-09 22:12:52 字数 1864 浏览 1 评论 0原文

我所做的


我有一个 Gridview,它用 imageID 填充了我的数据库。现在我设置了一个 onItemClickListner 来获取 imageID ->这有效!现在我想用该 imageID 搜索我的数据库,但它总是返回“null”,但这不应该是因为如果用这些 imageID 完全填充我的数据库。 表的结构是: RowID | RowID来源 |信息 在 Info 中,我存储了 imageID 的

问题


我必须如何更改光标才能通过 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;
    }

如何获取 imageID-back


    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();

其他信息:

  1. WhatIsInC,返回“0”。

如果您需要更多代码,请告诉我 提前感谢您的帮助! 此致 游猎

What I've done


I have a Gridview which is filled over my Database with the imageID's. Now I setted up a onItemClickListner with that I get the imageID -> this works!. Now I'd like to search my DB with that imageID, but it allways returns "null", but that shouldn't be because if filled my DB exactly with those imageID's.
The Structure of the Table is that: RowID | SOURCE | INFO
In Info i stored the imageID's

Question


How do I have to change Cursor that I can get the entries over INFO.
Down here you find the Code of my Cursor:

Code:


    //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;
    }

How I get the imageID-back


    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();

Additional Information:

  1. WhatIsInC, returns "0".

If you need more Code, just tell me
Thx for your help in advance!
Best Regards
safari

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫南 2024-12-16 22:12:52
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);
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;
  }

The db.query has the following parameters:

 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

So, in your query,

this.mDb.query(DATABASE_TABLE, new String[] { INFO, SOURCE },INFO + " = '" + info + "'" , null, null, null, null, null);

or

this.mDb.query(DATABASE_TABLE,new String[] {INFO, SOURCE},INFO + " = ?",new String[]
{info},null, null, null, null);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文