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 6723143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:32:01+00:00 2026-05-26T09:32:01+00:00

I am trying to iterate on my database records. but for some reason it

  • 0

I am trying to iterate on my database records. but for some reason it always return an empty cursor.
If I pull out from the emulator the database file file the ‘File explorer tab’ I can see the table and the data in it.

here is my code:

Cursor result = db.getReadableDatabase().rawQuery(
                    "SELECT _ID, STUDENT_NAME, STUDENT_GRADE, STUDENT_ADDRESS "
                            + "FROM students", null);
            while (!result.moveToNext())
            {
                int id = result.getInt(0);
                String studentName = result.getString(1);
                String studentGrade = result.getString(2);
                String studentAddress = result.getString(3);
                Log.d("Sqlitedemo", "ID=" + id + ", STUDENT_NAME=" + studentName +", STUDENT_GRADE="+studentGrade+", STUDENT_ADDRESS="+studentAddress);
            }
            result.close();

now while (!result.moveToNext()) always return false.

this is my DatabaseHelper class:

public class DatabaseHelper extends SQLiteOpenHelper
{
    private static final String DATABASE_NAME   = "db";
    static final String         STUDENT_NAME    = " STUDENT_NAME";
    static final String         STUDENT_GRADE   = "STUDENT_GRADE";
    static final String         STUDENT_ADDRESS = "STUDENT_ADDRESS";

    public DatabaseHelper(Context context)
    {
        super(context, DATABASE_NAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db)
    {
        // creating the table
        db
                .execSQL("CREATE TABLE students (_id INTEGER PRIMARY KEY AUTOINCREMENT, STUDENT_NAME TEXT, STUDENT_GRADE TEXT,  STUDENT_ADDRESS TEXT);");

        ContentValues cv = new ContentValues();

        cv.put(STUDENT_NAME, "Roi");
        cv.put(STUDENT_GRADE, "85");
        cv.put(STUDENT_ADDRESS, "Tel aviv");

        db.insert("students", STUDENT_NAME, cv);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        // TODO Auto-generated method stub

    }

}

any idea?

Thanks,
ray.

  • 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-26T09:32:02+00:00Added an answer on May 26, 2026 at 9:32 am
    Cursor result = db.getReadableDatabase().rawQuery(
                    "SELECT _ID, STUDENT_NAME, STUDENT_GRADE, STUDENT_ADDRESS "
                            + "FROM students", null);
    int id = result.getInt(0);
    String studentName = result.getString(1);
    String studentGrade = result.getString(2);
    String studentAddress = result.getString(3);
    if (result.moveToFirst())
    {
        Log.d("Sqlitedemo", "ID=" + id + ", STUDENT_NAME=" + studentName +", STUDENT_GRADE="+studentGrade+", STUDENT_ADDRESS="+studentAddress);
        while(result.moveToNext())
        {
            Log.d("Sqlitedemo", "ID=" + id + ", STUDENT_NAME=" + studentName +", STUDENT_GRADE="+studentGrade+", STUDENT_ADDRESS="+studentAddress);
        }
    }
    result.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am retrieving a fetch from my core data database and trying to iterate
I'm trying to iterate through all nodes, so I can print them out for
I'm trying to iterate through all the empty textboxes in a table and change
I'm trying to figure out how to iterate through a JSON object in an
I am trying to get metadata from an sqlite database. The main purpose for
I am trying to query a MySQL database using webpy. From the SQL query,
I've been trying to present my data from my database using PHP. My while
Using SQLite3 with Python 2.5, I'm trying to iterate through a list and pull
I've been working very long on trying to straighten this out, but I just
I'm trying to iterate all the controls on a form and enable ClearType font

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.