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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:00:17+00:00 2026-06-01T20:00:17+00:00

I created a simple database in Android. It has 3 columns RowID, UPCCode and

  • 0

I created a simple database in Android. It has 3 columns RowID, UPCCode and Title. I have sucessfully entered the data into the database using the NewBoston Tutorials on youtube. Now what I want is to restrict my database to 10 records (e.g. Last 10 searches) and I want to display them into a ListView in a new activity.

I am having problems regarding how to achieve that, cant find good help.. code posted below …

TenSearches.java

package com.rhuf.brandscan;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class TenSearches {
    public static final String KEY_ROWID="ID";
    public static final String KEY_UPC="upccode";
    public static final String KEY_TITLE="title";

    public static final String DATABASE_NAME="BrandscanDB";
    public static final String DATABASE_TABLE="ScanTable";
    public static final int DATABASE_VERSION=1;

    private DBHelper helper;
    private final Context context;
    private SQLiteDatabase BrandScanDB;

    public TenSearches(Context c)
    {
        context = c;
    }

    public TenSearches open() throws SQLException
    {
        helper = new DBHelper(context);
        BrandScanDB = helper.getWritableDatabase();
        return this;
    }

    public void close()
    {
        helper.close();
    }

    public long createEntry(String upc, String title)
    {
        ContentValues cv = new ContentValues();
        cv.put(KEY_UPC, upc);
        cv.put(KEY_TITLE, title);
        return BrandScanDB.insert(DATABASE_TABLE, null, cv);
    }

    public String getDataUPC()
    {
        String columns[]=new String[]{KEY_ROWID,KEY_UPC,KEY_TITLE};
        Cursor c = BrandScanDB.query(DATABASE_TABLE, columns, null, null, null, null, KEY_ROWID);
        String result;

        int iRow = c.getColumnIndex(KEY_ROWID);
        int iUPC = c.getColumnIndex(KEY_UPC);
        int iTitle = c.getColumnIndex(KEY_TITLE);

        //Make a listArray or Object Array from the Database entries
        return null;
    }
}

DBHelper.java

package com.rhuf.brandscan;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.rhuf.brandscan.TenSearches;

public class DBHelper extends SQLiteOpenHelper{

    public DBHelper(Context context) {
        super(context,TenSearches.DATABASE_NAME,null,TenSearches.DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("CREATE TABLE " +TenSearches.DATABASE_TABLE +" ("+
                TenSearches.KEY_ROWID +" INTEGER PRIMARY KEY AUTOINCREMENT, " +
                TenSearches.KEY_UPC +" TEXT NOT NULL, " +
                TenSearches.KEY_TITLE + " TEXT NOT NULL);");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS " + TenSearches.DATABASE_TABLE);
        onCreate(db);
    }

}
  • 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-01T20:00:18+00:00Added an answer on June 1, 2026 at 8:00 pm

    Don’t use a database for just 10 entries. Make a List of the last ten entries (a queue), and serialize that to a file. DBs are made for many, many entries and the problems a large amount of data causes, but you want to just store a few lines.

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

Sidebar

Related Questions

I have created a database for my android app which contains static data and
I'm trying to reindex a table in a simple database that I created using
I have created a simple windows service that periodically checks a remote database via
Could someone help me on this, I have created simple web services using axis2
I want to create simple login system using the SQLLIte I have created the
I have created a simple database in SQL Server Express which consists of three
I have some simple code which should create a database. package com.webfoo.android.databaseExample; import android.app.Activity;
I recently created my simple log4net database table for logging via the adonet appender..
Im working on the notepad tutorial from the android website. I have created a
I have a small problem with OrmLite on Android. When I increment the database

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.