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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:50:34+00:00 2026-05-16T22:50:34+00:00

I am creating my SQLite database for my App at runtime if it does

  • 0

I am creating my SQLite database for my App at runtime if it does not exist and insert rows if it does. Since it is supposed to be created at runtime and I have implemented it by creating a subclass of SQLiteOpenHelper and overriding the onCreate() method –

“Do I need to put anything in the /assets folder of my project?”

I am not using any Content Provider “Do I need to add any tags in the AndroidManifest.xml?”

Here is what I have done. The strings have been defined properly and I do not get any runtime exceptions.

Implementation of the SQLiteOpenHelper subclass.

public class MyDB extends SQLiteOpenHelper {

                   public MyDB(Context context) {
                    super(context, DATABASE_NAME, null,  DATABASE_VERSION );
                   }

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

                @Override
                public void onUpgrade(SQLiteDatabase db, int oldVersion, int 
                newVersion) {
                    Log.w("Example", "Upgrading database, this will drop tables and
                    recreate.");
                    db.execSQL("DROP TABLE IF EXISTS " +  USERAUTH_TABLE_NAME);
                    db.execSQL("DROP TABLE IF EXISTS " +  USERPREF_TABLE_NAME);
                    onCreate(db);
               }

}

Here is where I create an instance of the MyDB subclass of the SQLiteOpenHelper.

MyDB tdb = new MyDB(Activity.this); 
SQLiteDatabase db = tdb.getReadableDatabase();

Everything runs and when I go to the sqlite shell and write the following query

select * from table_name – it just tells me no such record exist. I set breakpoints and it seems after the getReadableDatabase() is called the @Override OnCreate() method is never executed which is where I execute the Create table SQLs. I have tried getWritableDatabase()
as well.

I dont understand why the tables are not being created. If anyone can help that would be awesome.

Thanks.

Query Text String#1

private static final String USERAUTH_TABLE_CREATE =
“CREATE TABLE ” + USERAUTH_TABLE_NAME + ” (” +
“number INTEGER NOT NULL,” +
“dip TEXT NOT NULL,” +
“email TEXT NOT NULL,” +
“password TEXT NOT NULL,” +
“flag INTEGER” + “);” ;

Query Text String #2

private static final String USERPREF_TABLE_CREATE = 
 "CREATE TABLE " + USERPREF_TABLE_NAME + " (" +
 "tpd TEXT NOT NULL ," +
 "cat TEXT NOT NULL" + ");";
  • 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-16T22:50:34+00:00Added an answer on May 16, 2026 at 10:50 pm

    If onCreate() is not being called, then the database has already been created for your app. The quickest way to solve it is to delete your project on the emulator (Settings –> Applications –> Your application), and then restart your application. Alternatively you could use ADB to just drop your database — it’s up to you. Restarting the app after dropping the database will call onCreate() because the database does not exist, and then your table creation sql will be run. onCreate() is only called if your database DOES NOT exist (so pretty much the first time you call the database in your code.

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

Sidebar

Related Questions

i am creating an app that needs a database. i created it using sqlite
I am creating an app that needs a database. I created it using sqlite
I'm creating a dictionary app. My Sqlite database is about 15MB and on the
I'm creating an app that has a database using sqlite. On my app I've
I'm creating my first android app that will make use of SQlite. I have
I have an events app which gets events data from sqlite database and displays
I am creating a sqlite database for my mobile app. once the user has
I am creating an iphone app that will run an SQLite database. I want
I have an app that uses an sqlite database. Currently I have a database
I'm creating a simple app that stores data into a sqlite database and retrieves

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.