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

  • Home
  • SEARCH
  • 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 4622176
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:48:23+00:00 2026-05-22T02:48:23+00:00

I am really struggling with using the SqlLite in my App; I have set

  • 0

I am really struggling with using the SqlLite in my App;

I have set up a database helper class that extends from SQLiteOpenHelper

public class DatabaseHelper extends SQLiteOpenHelper {

In the OnCreate I am Creating about 6 tables:

public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE myTestTable (Id INTEGER PRIMARY KEY , "
            + "info TEXT," + 
            + "TopLeft TEXT")); <-- example insert

}

When my App starts I am parsing some xml and entering the data into the table, and I have checked the database and all is in there and my tables created correctly.

When I go to call the data it is gone!
I have lots of different queries within my dbhelper class and on each activity I;m re initilizing the class so I can get at my function within the class.

I assume this is not the way to do it as it runs my oncreate again and wipes all my tables (or at least this is when it appears to be doing as I check the DB after I’ve tried calling data from it and it’s empty!

I was under the impression the oncreate only ran once, but this is obviously not the case as it appears to be recreating my DB everytime and wiping my data!

Where are you meant to initialize the the dbhelper class and how do you stop it recreating the tables? I need the data to persist even when the app closes!

I’m confused!

If this doesn’t make sense please ask specific questions on how I can clarify it!

UPDATE

I have found I can add

CREATE TABLE IF NOT EXISTS

Which stops it recreating the tables, but it still doesn’t seem right calling the oncreate every time..

  • 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-22T02:48:24+00:00Added an answer on May 22, 2026 at 2:48 am

    You could put a wrapper class around it?

    public class DbAdapter
    {
    
      // database details
      private static final String DATABASE_NAME = "dbname";
      private static final int DATABASE_VERSION = 1;
    
      // where we're running
      private final Context mCtx;
    
      private static class DatabaseHelper extends SQLiteOpenHelper
      {
        DatabaseHelper(Context context)
        {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
    
        @Override
        public void onCreate(SQLiteDatabase db)
        {
          // your initial database create statements go here
          db.execSQL(DATABASE_CREATE);
        }
    
        // if you need to recreate the database, you just up the version number
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
        {
          // drop commands for each table goes here
          db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
          onCreate(db);
        }
      }
    
      public DbAdapter(Context ctx)
      {
        this.mCtx = ctx;
      }
    
      public DbAdapter open() throws SQLException
      {
        mDbHelper = new DatabaseHelper(mCtx);
        mDb = mDbHelper.getWritableDatabase();
        return this;
      }
    
      public void close()
      {
        mDbHelper.close();
      }
    
      // other database methods can go here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am really struggling with the facebook api. A have created a app, an
Really struggling to figure this out. Just trying to take in data from php
I am really struggling with understanding the difference between these two. From my textbook,
I'm really struggling with something that should be a simple matter: Showing a user
really struggling to resolve this issue. using nhibernate Im trying to join two different
I've been using RDBMSes since college and am really struggling with the underlying concepts
Hi I am really struggling making code for a function that 'returns an array
I am really struggling with linking menus together. The app I want to create
I have a working statement in PHP using the simple dom parser that I
I'm really struggling with using the CallNtPowerInformation function in C#. I need to get

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.