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

  • SEARCH
  • Home
  • 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 8790109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:34:01+00:00 2026-06-13T22:34:01+00:00

I am having trouble to get all rows data from sql. DatabaseHandler.java public HashMap<String,

  • 0

I am having trouble to get all rows data from sql.

DatabaseHandler.java

public HashMap<String, String> getChannelDetails(){
    HashMap<String,String> channels = new HashMap<String,String>();
    String selectQuery = "SELECT  * FROM " + TABLE_CHANNEL;

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            channels.put("title", cursor.getString(1));
            channels.put("url", cursor.getString(2));
            channels.put("create_at", cursor.getString(3));
        } while (cursor.moveToNext());
        Log.d("SELECT", channels.toString());
        Log.d("Count", Integer.toString(cursor.getCount()));
    }

    cursor.close();
    db.close();
    // return channels
    return channels;
}

Showresult.java

for(int i = 0; i < 13; i++){
         HashMap<String, String> allchannel = db.getChannelDetails(); 
         String id = allchannel.get("id");
         String title = allchannel.get("title");
         String url = allchannel.get("url");
         String date = allchannel.get("created_at");
         titles[i] = title;
         Toast.makeText(context,titles[i]+" "+url+" "+ date, Toast.LENGTH_SHORT).show();
         }

The cursor.getCount() have 13, however the output show only last row data repeatedly.

  • 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-06-13T22:34:03+00:00Added an answer on June 13, 2026 at 10:34 pm

    change your method to following:

    public ArrayList<HashMap<String, String>> getChannelDetails(){
    ArrayList<HashMap<String, String>> list=new ArrayList<HashMap<String, String>>();
        String selectQuery = "SELECT  * FROM " + TABLE_CHANNEL;
    
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);
        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                HashMap<String,String> channels = new HashMap<String,String>();
    
                channels.put("title", cursor.getString(1));
                channels.put("url", cursor.getString(2));
                channels.put("create_at", cursor.getString(3));
                list.add(channels);
            } while (cursor.moveToNext());
            Log.d("Count", Integer.toString(cursor.getCount()));
        }
    
        cursor.close();
        db.close();
        // return channels
        return list;
    }
    

    now use this list to iterate through the results.

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

Sidebar

Related Questions

testQuery() is the method I use to get all rows from table CATEGORIES public
I am having trouble in returning data in php from an SQL query. here
I am having serious trouble with trying to get all the forms on a
Having trouble getting my POST arrays to show all checkbox values from my form.
I am attempting to get all the data from a MySQL db with PHP,
Having trouble looping through multiple rows in a SQL table and getting the info
I'm having trouble getting this loop to return all of the rows that I
I'm having trouble returning data from my controller using an ajax post function. What
I am having trouble, I am trying to get updates from a messages table
With MVC4, I'm having some trouble inserting new rows into my database (SQL Compact).

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.