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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:06:10+00:00 2026-06-04T15:06:10+00:00

I am trying to get information from my database and put it into a

  • 0

I am trying to get information from my database and put it into a string to print it on screen. i thought i could use the code below to do it but it gives out some information about the cursor instead of the information inside the cursor.

datasource = new DataBaseHelper(this);
datasource.open();
Cursor c = datasource.getAllGoals();
startManagingCursor(c);
String g = c.toString();
goal.setText(g);
datasource.close();
  • 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-04T15:06:12+00:00Added an answer on June 4, 2026 at 3:06 pm

    The cursor can be thought of as a pointer to some underlying data. Running c.toString() on the cursor object would print the default Cursor class’ implementation of its string representation (an at-sign character @ and the unsigned hexadecimal representation of the hash code of the object) which is not what you want.

    To retrieve underlying database data, you will need to call c.getString(columnIndex) (source), or whatever column datatype you require for that particular column index.

    Here’s an example modified from source:

    Say you have created a table

    private static final String DATABASE_CREATE = 
                "create table comments ( "
                + "_id integer primary key autoincrement, "
                + "comment text not null);";
    

    and your getAllGoals function returns a cursor which points to data about both _id and comment. Now you only want to show the details about the comment column. So you have to run c.getString(1). Suppose your getAllGoals function returns a cursor which only points to data about the comment column. Now you have to run c.getString(0).

    I would recommend that you download the source code in the provided example and go through how data is retrieved from a cursor.

    EDIT:

        public List<Comment> getAllComments() {
            List<Comment> comments = new ArrayList<Comment>();
    
            Cursor cursor = database.query(MySQLiteHelper.TABLE_COMMENTS,
                    allColumns, null, null, null, null, null);
    
            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {//retrieve data from multiple rows
                Comment comment = cursorToComment(cursor);
                comments.add(comment);
                cursor.moveToNext();
            }
            // Make sure to close the cursor
            cursor.close();
            return comments;
        }
    
        private Comment cursorToComment(Cursor cursor) {
            Comment comment = new Comment();
            comment.setId(cursor.getLong(0));
            comment.setComment(cursor.getString(1));
            return comment;
        }
    

    source

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

Sidebar

Related Questions

I am trying to get some information from our database and then use it
I'm trying to get information from a cookie into Alfresco Share. I have a
I am trying to use python's telnetlib module to get information from a remote
I am trying to get information from a database, convert it to a list
I'm trying to get some information from ebay api and store it in database
I am trying to get all the users information from the database and check
I am trying to get information from 3 tables in my database. I am
Here is my basic situation. I'm trying to use NHibernate to get information from
I am trying to get information from an SQL database using python I was
Hi I am trying to get information on an Oracle package directly from PHP

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.