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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:33:23+00:00 2026-06-15T03:33:23+00:00

I need multiple tables in my application. For this I’ve created separate subclasses of

  • 0

I need multiple tables in my application. For this I’ve created separate subclasses of SQLiteOpenHelper to insert/remove/update data for different tables. My question is how can I make sure all these subclasses uses same instance of SQLiteDatabase across the entire code. Though I’ve made each subclass a singleton. However, I couldn’t work around the issue of using a common SQLiteDatabase instance across the entire code.

PS: I don’t want to use a ContentPovider or create a single SQLiteOpenHelper subclass as this would complicate my code.

  • 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-15T03:33:24+00:00Added an answer on June 15, 2026 at 3:33 am

    I don’t really see where you’re struggling at using a common SQLiteOpenHelper. You just have to duplicate what you do for one table ! Create a custom class that extends SQLiteOpenHelper and do the duplication.

    public class SQLiteCustomBase extends SQLiteOpenHelper {
    
        private static final String CREATE_BDD_1 = "CREATE TABLE ...";
        private static final String CREATE_BDD_2 = "CREATE TABLE ...";
    
        public SQLiteCustomBase(Context context, String name, CursorFactory factory, int version) {
            super(context, name, factory, version);
        }
    
        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL(CREATE_BDD_1);
            db.execSQL(CREATE_BDD_2);
        }
    
        @Override
        public void onOpen(SQLiteDatabase db) {}
    
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE " + Vars.TABLE_1 + ";");
            db.execSQL("DROP TABLE " + Vars.TABLE_2 + ";");
            onCreate(db);
        }
    }
    

    and then in the class where you perform some database actions :

    public class HandlerClass {
        private SQLiteDatabase db;
        private SQLiteCustomBase customBase;
    
        public HandlerClass(Context context){
            customBase = new SQLiteCustomBase(context, Vars.NAME_DB, null, Vars.VERSION_DB);
        }
    
        public void open(){
            db = customBase.getWritableDatabase();
        }
    
        public void openForRead(){
            db = customBase.getReadableDatabase();
        }
    
        public void close(){
            db.close();
        }
    
        public SQLiteDatabase getDB(){
            return db;
        }
    }
    
    void myMethods()
    {
        bdd.insert(Vars.TABLE_1, null, values);
        bdd.insert(Vars.TABLE_2, null, values);
    }
    etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple tables that need to be merged into one. SELECT name, SUM(money)
I need to split an amount into multiple part and insert into an table
I am developing LOB application, where I will need multiple dialog windows (and displaying
I have an application that needs to join tables from multiple databases into a
I use a database with multiple tables in my application. I have an XML
I am running fulltext queries on multiple tables on MySQL 5.5.22. The application uses
I need to select multiple table and one of it is transposed, my table
Hi I need multiple tabs in my android screen, which i got by TabHost
Apologize if i am wrong, i am new to metro apps i need multiple
I need to append multiple nodes to a container. Rather than doing a slow

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.