Skip to content
Advertisement

How to get row cursor with primary key android

I have a table with the following

JavaScript

I am trying to get all the data at a given rowid

JavaScript

I get an error

JavaScript

I did populate the table. How do I return a cursor based on the position of entry.

Advertisement

Answer

How do I return a cursor based on the position of entry

First, your method getRowCursor() should return a Cursor.
Also, you should not close the returned cursor because I assume that you want to use its results somehow.

Your code with the method rawQuery() should work like this:

JavaScript

But, the safe and recommended way to pass parameters to a query is with ? placeholders instead of concatenating them inside the sql statement and passing them as array items in the 2nd argument of rawQuery():

JavaScript

Note that moveToFirst() moves the cursor’s index at the 1st row of the cursor (if it exists).
I commented out this call, because you should use it after you call getRowCursor() like this:

JavaScript

and when you are done with the cursor:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement