开发者

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

开发者 https://www.devze.com 2023-01-11 04:21 出处:网络
See title for explanation. Here is the method I\'m using: public Cursor getClientByName(String name) throws SQLException {

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

精彩评论

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