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

The Archive Base Latest Questions

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

New to using databases, so not sure where my error lies to be honest.

  • 0

New to using databases, so not sure where my error lies to be honest. Here is my code:

Creating the database

    private static final String DATABASE_CREATE =
    "create table job_details (_id integer primary key autoincrement, "
    + "company text not null, advertised text, status text not null, position text not null, " +
    "wage text, hours text, address text, " +
    "email text, number text, notes text);";

    @Override
    public void onCreate(SQLiteDatabase db){
        db.execSQL(DATABASE_CREATE);
    }

Creating a row

     public long createJob(String company, String advertised, String status, String position, String wage, String hours,
        String address, String email, String number, String notes) {

    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_COMPANY, company);
    initialValues.put(KEY_ADVERTISED, advertised);
    initialValues.put(KEY_STATUS, status);
    initialValues.put(KEY_POSITION, position);
    initialValues.put(KEY_WAGE, wage);
    initialValues.put(KEY_HOURS, hours);
    initialValues.put(KEY_ADDRESS, address);
    initialValues.put(KEY_EMAIL, email);
    initialValues.put(KEY_NUMBER, number);
    initialValues.put(KEY_NOTES, notes);

    return mDb.insert(DATABASE_TABLE, null, initialValues);
}

Getting a cursor to all rows in table

     public Cursor fetchAllJobs() {

    return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_COMPANY,
            KEY_ADVERTISED, KEY_STATUS, KEY_POSITION, KEY_WAGE, KEY_HOURS,
            KEY_ADDRESS, KEY_EMAIL, KEY_NUMBER, KEY_NOTES}, null,
            null, null, null, null);
}

Using cursor to log some of the attributes of all the rows

    private void getAllData(){
    Cursor c = mDbHelper.fetchAllJobs();
    startManagingCursor(c);
    do{
        if(c.moveToFirst()){
            String company;
            String position;
            String number;

            int companyColumn = c.getColumnIndex(JobsDbAdapter.KEY_COMPANY);
            int positionColumn = c.getColumnIndex(JobsDbAdapter.KEY_POSITION);
            int numberColumn = c.getColumnIndex(JobsDbAdapter.KEY_NUMBER);

            do{
                company = c.getString(companyColumn);
                position = c.getString(positionColumn);
                number = c.getString(numberColumn); 
            }while(c.moveToNext());

            Log.d(TAG, "Company is = "+company);
            Log.d(TAG, "Position is = "+position);
            Log.d(TAG, "Number is = "+number);
        }
    }while(c.moveToNext());
}

When I use this code, the output/logged values are just those contained in the last row that I tried to enter in the database. I am not sure if I am entering the data wrong, or looking up the database wrong.

  • 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-26T10:40:33+00:00Added an answer on May 26, 2026 at 10:40 am

    This is incorrect:

     do{
                company = c.getString(companyColumn);
                position = c.getString(positionColumn);
                number = c.getString(numberColumn); 
            }while(c.moveToNext());
    

    When you want to read what a cursor is actually pointing to you don’t need to move it. A cursor points to the full record.

    Also your if statment always move the cursor back to the first result. That’s probably why you were only seeing the first row. Try this instead.

    private void getAllData(){
      Cursor c = mDbHelper.fetchAllJobs();
      startManagingCursor(c);
    
      while(c.moveToNext()){
    
            String company;
            String position;
            String number;
    
            int companyColumn = c.getColumnIndex(JobsDbAdapter.KEY_COMPANY);
            int positionColumn = c.getColumnIndex(JobsDbAdapter.KEY_POSITION);
            int numberColumn = c.getColumnIndex(JobsDbAdapter.KEY_NUMBER);
    
    
            company = c.getString(companyColumn);
            position = c.getString(positionColumn);
            number = c.getString(numberColumn); 
    
    
            Log.d(TAG, "Company is = "+company);
            Log.d(TAG, "Position is = "+position);
            Log.d(TAG, "Number is = "+number);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed error in my application and not sure why.
I am new to Python, and I'm working on writing some database code using
I'm starting a new semester and for my class relational databases they are using
I am new to using the SQLite database in iphone apps. I have created
I'm attaching a new database programatically using VB.net application. I wrote DB scripts and
I'm trying to insert some new objects into a firebird database using NHibernate. I
I'm using the new ASP.Net ListView control to list database items that will be
I am using PDO with PHP to create a new database and then a
I'm fairly new to database programming in WinForms, and have been using BindingSource, DataSet,
I am getting a Fatal Error on using a ExecuteNonQuery(). I'm new to working

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.