Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6123007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:57:55+00:00 2026-05-23T15:57:55+00:00

I have a database and I am doing a query to it using Cursor

  • 0

I have a database and I am doing a query to it using

Cursor mCursor = mapDb.query(MY_TABLE, new String[] {KEY_ONEID, KEY_TWOID}, "trim("+KEY_TWOID + ") != '' ", null, null, null, null);

which in SQL terms literally means:
SELECT OneId, TwoId FROM auth WHERE trim(TwoId) != ''

Using the raw SQL query this works in my SQLite browser to show me the rows in question, so the Cursor object should contain the same results.

Secondly in my java method I am using a condition to check if this result has anything

    if(mCursor.getColumnIndex(KEY_ONEID) > -1)  //if > -1 then the mCursor returned a row
    {

       if(mCursor.getString(mCursor.getColumnIndex(KEY_ONEID)).contains(id)) //breaks here
                return mCursor.getString(mCursor.getColumnIndex(KEY_TWOID));
            else
                return "";
    }

But for some reason, even though the mCursor hashmap should have all the values returned, this next conditional statement

mCursor.getString(mCursor.getColumnIndex(KEY_ONEID)).contains(id)

still returns: An exception occurred: android.database.CursorIndexOutOfBoundsException

this is the line that throws the exception: mCursor.getString(mCursor.getColumnIndex(KEY_ONEID)) and so does my next item in the return statement

I’m baffled at how to retrieve a particular row value then! because I have pulled the database and run the same query and can clearly see that both of the values I want, do in fact exist!

the Cursor function doesn’t provide many other ways to retrieve values, so insight appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:57:56+00:00Added an answer on May 23, 2026 at 3:57 pm

    You need to position the Cursor to the first row before you can get data from it. To do this you can call: mCursor.moveToFirst(). Also, this method call returns a boolean, which will be false if there are no results; so you can also use it to guard against that case.

    If you need to iterate through multiple results, then after calling mCursor.moveToFirst(), you can use the mCursor.moveToNext() method go through the result rows one by one. Once again, this returns false when it reaches the end of the data set.

    Hope that makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using System.Data.Sqlite to access SQLite database in C#. I have a query
I have the following code. int phoneContactID = new Random().nextInt(); Cursor contactLookupCursor = context.getContentResolver().query(
Problem: Need to store field value when doing this query on my database. Have
I'm doing a database for storing my eBook collection. Most of them have the
I have a database that contains a date and we are using the MaskedEditExtender
I'm doing a simple query on the database, a search on two columns. I
I have a classifieds database which is displayed to users depending on their query,
I have a database where I need to query to get records from one
I have a query doing something like: SELECT FieldX, FieldY FROM A WHERE FieldW
The log reports that the database or cursor was not closed. I basically have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.