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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:48:21+00:00 2026-06-10T06:48:21+00:00

I am new to Android and I have to create an application where I

  • 0

I am new to Android and I have to create an application where I need to use a SQLite database.
I am not so well equipped with the SQLite.

Could you tell me what the purpose and use of the SQLiteOpenHelper class, and provide a simple database creation and insertion example?

  • 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-10T06:48:23+00:00Added an answer on June 10, 2026 at 6:48 am

    Sqlite helper class helps us to manage database creation and version management.
    SQLiteOpenHelper takes care of all database management activities. To use it,

    1.Override onCreate(), onUpgrade() methods of SQLiteOpenHelper. Optionally override onOpen() method.

    2.Use this subclass to create either a readable or writable database and use the SQLiteDatabase’s four API methods insert(), execSQL(), update(), delete() to create, read, update and delete rows of your table.

    Example to create a MyEmployees table and to select and insert records:

    public class MyDatabaseHelper extends SQLiteOpenHelper {
    
        private static final String DATABASE_NAME = "DBName";
    
        private static final int DATABASE_VERSION = 2;
    
        // Database creation sql statement
        private static final String DATABASE_CREATE = "create table MyEmployees
                                     ( _id integer primary key,name text not null);";
    
        public MyDatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
    
        // Method is called during creation of the database
        @Override
        public void onCreate(SQLiteDatabase database) {
            database.execSQL(DATABASE_CREATE);
        }
    
        // Method is called during an upgrade of the database,
        @Override
        public void onUpgrade(SQLiteDatabase database,int oldVersion,int newVersion){
            Log.w(MyDatabaseHelper.class.getName(),
                             "Upgrading database from version " + oldVersion + " to "
                             + newVersion + ", which will destroy all old data");
            database.execSQL("DROP TABLE IF EXISTS MyEmployees");
            onCreate(database);
        }
    }
    

    Now you can use this class as below,

    public class MyDB{  
    
        private MyDatabaseHelper dbHelper;  
    
        private SQLiteDatabase database;  
    
        public final static String EMP_TABLE="MyEmployees"; // name of table 
    
        public final static String EMP_ID="_id"; // id value for employee
        public final static String EMP_NAME="name";  // name of employee
    
        /** 
         * 
         * @param context 
         */  
        public MyDB(Context context){  
            dbHelper = new MyDatabaseHelper(context);  
            database = dbHelper.getWritableDatabase();  
        }
    
    
        public long createRecords(String id, String name){  
            ContentValues values = new ContentValues();  
            values.put(EMP_ID, id);  
            values.put(EMP_NAME, name);  
            return database.insert(EMP_TABLE, null, values);  
        }    
    
        public Cursor selectRecords() {
            String[] cols = new String[] {EMP_ID, EMP_NAME};  
            Cursor mCursor = database.query(true, EMP_TABLE,cols,null  
                , null, null, null, null, null);  
            if (mCursor != null) {  
                mCursor.moveToFirst();  
            }  
            return mCursor; // iterate to get each value.
        }
    }
    

    Now you can use MyDB class in you activity to have all the database operations. The create records will help you to insert the values similarly you can have your own functions for update and delete.

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

Sidebar

Related Questions

I am new to phonegap and android, I have create a hello world application
Hello i am new in developing Android applications, I need to create an application
I am a new android developer . I have create a quiz application where
i am creating a new android application.i am using the table layout. I have
I'm new to android apps development and I have a basic sqlite question. What
I am new to Android. I have tried an sample application for status bar
Im new to android development. Now im trying to use sqlite db. I created
I need to work on the internals of android, especially create and test new
I have tried to create a android application that sends a serialzed object from
I am developing an android application. Now i have created one function which create

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.