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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:49:55+00:00 2026-06-13T11:49:55+00:00

I have a class DatabaseHandler. I have overridden the onCreate(SQLiteDatabase db) method with the

  • 0

I have a class DatabaseHandler. I have overridden the onCreate(SQLiteDatabase db) method with the following code :

    String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_SONG + "(" + ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                            SONG_TITLE + " TEXT," + ARTIST_NAME + " TEXT," + GENRE + " TEXT," +
                            SONG_PATH + " TEXT" + ")";
    db.execSQL(CREATE_TABLE);

but I found that there were extra items getting appended to the TABLE_SONG everytime I opened the emulator as a result of which even though I had 6 songs in the sdcard the database showed 454 songs. This forced me to drop the table with a thought of recreating it again. But now I am stuck that the table could not be found or rather is not getting created. Shouldnt it be that the onCreate() method should get called everytime when I create an object of this class?

  • 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-13T11:49:55+00:00Added an answer on June 13, 2026 at 11:49 am

    I agree with waqas please find sample code below

        @Override
            public void onCreate(SQLiteDatabase db) {
           String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME
                        + ... ) ";
    db.execSQL(CREATE_TABLE);}
    
    @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // Drop older table if exists
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
                    onCreate(db);
    }
    

    EDIT
    USE of onUpgrade()

    It is called when you construct a SQLiteOpenHelper with version newer than the version of the opened database. What to do depends on the changes in the database that are made between the old and new versions. The only case when you don’t drop a changed table is when the change is noting more than an added column. Then you can use ALTER TABLE statement to add the new column to the table signature.

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

Sidebar

Related Questions

Please have a look at the following code DatabaseHandler.java public List getDetails(String name) {
I have an sqlite table with the following structure: String CREATE_ACHIEVEMENTS_TABLE = CREATE TABLE
I have class with a forwarding method foo : void foo( Concrete c, String
I have class with back reference: public class Employee : Entity { private string
We have class lua. In lua class there is a method registerFunc() which is
I have class GUI so I can create object like this: GUI g1 =
I have class to create user and return the info of user (success). class
I have created a class call DatabaseHandler extending SQLiteOpenHelper. I want to explicting deleted
I am using this code in the DatabaseHandler: public class DatabaseHandler extends SQLiteOpenHelper {
I have class method that returns a list of employees that I can iterate

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.