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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:43:11+00:00 2026-06-17T10:43:11+00:00

I am developing an Android application that has a database having 14-15 tables. I

  • 0

I am developing an Android application that has a database having 14-15 tables. I want to access these tables obviously for querying, inserting, deleting etc.

Should I make a single helper that would open the database and then create a single adapter that would access it and query it as I plan to? Or make a helper for each table?

I am confused about this point. The first option seems more realistic to me because I wouldn’t need to open the database multiple times.

  • 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-17T10:43:12+00:00Added an answer on June 17, 2026 at 10:43 am

    Create a class that extends from SQLiteOpenHelper and make method for each one.
    One for insert, one for delete, one for update and one from retrieving ResultSet.
    Here is an example:

    public class Db extends SQLiteOpenHelper {
        static final int    version=1;
        static final String dbName="phoneBook";
        static final String dbtable="data";
        Context cont;
    
        public Db(Context context) 
        {
            super(context, dbName, null, version);
            cont = context;
        }
    
        public void onCreate(SQLiteDatabase db) 
        {
            try {
                String sql = "CREATE TABLE "+dbtable+" (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, phone TEXT)";
                db.execSQL(sql);
            } catch (SQLException e) {
                Toast.makeText(cont, e.toString(), Toast.LENGTH_LONG).show();
            }
        }
    
        public void addContact(String name, String number) 
        {
            try 
            {
                SQLiteDatabase db = getWritableDatabase();
                String sql = "INSERT INTO "+dbtable+" VALUES(NULL,'"+name+"', '"+number+"')";
                db.execSQL(sql);
                db.close();
            } catch (SQLException e) {
                Toast.makeText(cont, e.toString(), Toast.LENGTH_LONG).show();
            }
        }
        public void updateContact(int sid, String name, String number) {
            try {
                SQLiteDatabase db = getWritableDatabase();
                String sql = "UPDATE "+dbtable+" SET name = '"+name+"', phone = '"+number+"' WHERE id = "+sid;
                db.execSQL(sql);
                db.close();
            } catch (SQLException e) {
                Toast.makeText(cont, e.toString(), Toast.LENGTH_LONG).show();
            }
        }
        public ArrayList<String> getContactByPhone(String number) {
            try {
                SQLiteDatabase db=this.getReadableDatabase();
                ArrayList<String> al = new ArrayList<String>();
                Cursor cur = db.rawQuery("SELECT * from "+dbtable+" WHERE phone like '%"+number+"%'",null);
                while(cur.moveToNext())
                    al.add(cur.getInt(0)+","+cur.getString(1)+","+cur.getString(2));
                db.close();
                return al;
            } catch(SQLException e) {
                Toast.makeText(cont, e.toString(), Toast.LENGTH_LONG).show();
            }
            return null;
        }
    
        public ArrayList<String> getContactByName(String sname) {
            try {
                SQLiteDatabase db=this.getReadableDatabase();
                ArrayList<String> al = new ArrayList<String>();
                Cursor cur = db.rawQuery("SELECT * from "+dbtable+" WHERE name like '%"+sname+"%'",null);
                while(cur.moveToNext())
                    al.add(cur.getInt(0)+","+cur.getString(1)+","+cur.getString(2));
                db.close();
                return al;
            } catch(SQLException e) {
                Toast.makeText(cont, e.toString(), Toast.LENGTH_LONG).show();
            }
            return null;
        }
    
        public ArrayList<String> getAllContact() {
            try {
                SQLiteDatabase db=this.getReadableDatabase();
                ArrayList<String> al = new ArrayList<String>();
                Cursor cur = db.rawQuery("SELECT * from "+dbtable,null);
                while(cur.moveToNext())
                    al.add(cur.getInt(0)+","+cur.getString(1)+","+cur.getString(2));
                db.close();
                return al;
            } catch(SQLException e) {
                Toast.makeText(cont, e.toString(), Toast.LENGTH_LONG).show();
            }
            return null;
        }
    
        public void deleteContact(int sid) {
            try {
                SQLiteDatabase db = getWritableDatabase();
                String sql = "DELETE FROM "+dbtable+" WHERE id = "+sid;
                db.execSQL(sql);
                db.close();
            } catch (SQLException e) {
                Toast.makeText(cont, e.toString(), Toast.LENGTH_LONG).show();
            }
        }
    
        public void deleteData() {
            try {
                SQLiteDatabase db = getWritableDatabase();
                db.execSQL("DELETE FROM "+dbtable);
                db.close();
            } catch (SQLException e) {
                Toast.makeText(cont, e.toString(), Toast.LENGTH_LONG).show();
            }
        }
    
        public void showAll() {
            try {
                SQLiteDatabase db = getReadableDatabase();
                Cursor cur = db.rawQuery("SELECT * from "+dbtable, null);
                while(cur.moveToNext())
                    Toast.makeText(cont, cur.getString(1)+" "+cur.getString(2), Toast.LENGTH_LONG).show();
                db.close();
            } catch (SQLException e) {
                Toast.makeText(cont, e.toString(), Toast.LENGTH_LONG).show();
            }
        }
    
        public int getCount() {
            int total = 0;
            try {
                SQLiteDatabase db = getReadableDatabase();
                Cursor curs = db.rawQuery("SELECT * FROM "+dbtable+" WHERE 1",null);
                total = curs.getCount();            
                db.close();
            } catch (SQLException e) {
                Toast.makeText(cont, e.toString(), Toast.LENGTH_LONG).show();
            }
            return total;
        }
    
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            try {
                db.execSQL("DROP TABLE IF EXISTS "+dbtable);
                onCreate(db);
            } catch (SQLException e) {
                Toast.makeText(cont, e.toString(), Toast.LENGTH_LONG).show();
            }
        }
    
    }
    

    `

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

Sidebar

Related Questions

Hi an developing drawing android application. in that i want to add a sticker(image)
I am developing an android mobile application using eclipse. I need a database that
I'm developing an Android Application that has three very similar Activities. I would like
I'm develloping an android application that has a local database which synchronizes whith an
We're developing an android application that has several different tabs. We've been trying to
I was developing android application that has backup to google drive feature. I have
I am currently developing an Android Application that has Google Maps integrated into it.
The Plan: I'm developing an android application that is heavily database driven (as in,
I'm developing an Android application that has many activities. I have a Logout Activity
I'm developing an Android application that has 10 different activities with the same constant

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.