0

I am trying to get data from my SQLite table, I am running this query:

SQLiteDatabase db = this.getWritableDatabase();
// int memberId = 1234
Cursor rs = db.rawQuery("select username, password from users where memberId = ? limit 1", new String[]{String.valueOf(memberId)});
System.err.println("Rows: " + rs.getCount());

The output is Rows: 0

But when I run this query:

Cursor rs = db.rawQuery("select username, password, memberId from users limit 1", new String[]{});
rs.moveToFirst();
System.err.println(rs.getString(0) + ":" + rs.getString(1) + ":" + rs.getString(2));

I get username:xxxx:1234

How come when I add a where clause this is breaking?

Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338

1 Answers1

1

As @Ryan Naddy pointed out - the difference between exposition one and exposition 2 is that you call "moveToFirst()" - you need to do this as the cursor is positioned before the first entry.

See this article.

Community
  • 1
  • 1
Dave G
  • 9,639
  • 36
  • 41