开发者

Querying SQLite DB in Android Activity - saying no column found, although it exists

See title for explanation.

Here is the method I'm using:

public Cursor getClientByName(String name) throws SQLException {

    name = name.trim();

    Cursor mCursor = 

        mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_NAME}, KEY_NAME + "=" + name, null,
                null, null, null, null);

    if (mCursor != null) {
        mCursor.moveToFirst();
    }

    return mCursor;

}

And here is the call to the method:

list.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
            int position, long vId) {

            String name = ((TextView) view).getText().t开发者_运维问答oString();

            // Toast.makeText(AvoidForeclosure.this, name, Toast.LENGTH_LONG).show();

            Cursor cD = db.getClientByName(name);
            cD.moveToLast();
            int id = cD.getInt(0);

          Intent intent = new Intent();
          intent.setClass(view.getContext(), CurrentMarketValue.class);
          intent.putExtra("clientId", id);
          startActivity(intent);

        }
      });

Any idea why it would be throwing the "No Column Found with name=Test", although my DB explorer shows there is indeed a column named name and a value in a row named Test?


public Cursor getClientByName(String name) throws SQLException {

        name = name.trim();

        String q = "SELECT _id, name FROM " + DATABASE_TABLE + " WHERE name=?";

        Cursor mCursor = mDb.rawQuery(q, new String[] { name });


        if (mCursor != null) {
            mCursor.moveToFirst();
        }

        return mCursor;

    }

Fixes this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜