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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:34:10+00:00 2026-05-27T19:34:10+00:00

I have created a SQLite file and putted it on to assets folder. Now

  • 0

I have created a SQLite file and putted it on to assets folder. Now I am able to read the data from that file but I don’t have any idea how to write to this database file. I need to take the user name and score and store that in to that database file. I searched on the web and on the SO also but there are examples for the normal database insertion.

Can any one tell me how to store the values into database file. I need to store the username and score. Just think this to as Strings and please give me a example for it.

  • 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-27T19:34:11+00:00Added an answer on May 27, 2026 at 7:34 pm

    You should not create database in the assets folder as we can only read data from assets folder.

    Infact you should create the database in the default internal folder i.e data/data/[package-name]/databases OR you also can create your database in the sdcard and can perform read-write operation but of course it will not run if there is no sdcard.

    The following is the code for creating databse in sdcard:-

        private SQLiteDatabase db;
        private static Context cntxt;
    
        public static File filename = null;
        public static String DATABASE_FILE_PATH_EXTERNAL = null;
    
        public DBHelper(Context context) {
                super(context, DATABASE_NAME, null,1);
                cntxt = context;
                try{
                    try{
                        filename = Environment.getExternalStorageDirectory();
                    }catch(Exception e){
                        Toast.makeText(DbHelper.cntxt, "Please Insert SD card To create Database", Toast.LENGTH_LONG).show();
                        Log.e("Log",e.getMessage(),e.fillInStackTrace());
                    }
    
                    DATABASE_FILE_PATH_EXTERNAL = filename.getAbsolutePath()+File.separator+DATABASE_NAME;
    
                    //  db = SQLiteDatabase.openDatabase(DATABASE_FILE_PATH_EXTERNAL, null, SQLiteDatabase.OPEN_READWRITE + SQLiteDatabase.CREATE_IF_NECESSARY);
                }catch(Exception e){
    
                    Log.e("Log",e.getMessage(),e.fillInStackTrace());
                }
            }
    
    
    
            @Override
            public synchronized SQLiteDatabase getWritableDatabase() {
                // TODO Auto-generated method stub
                try{
                    db = SQLiteDatabase.openDatabase(DATABASE_FILE_PATH_EXTERNAL, null, SQLiteDatabase.OPEN_READWRITE + SQLiteDatabase.CREATE_IF_NECESSARY);
                    try{
                        onCreate(db);
                    }catch(Exception e){
                        Log.e("Log",e.getMessage(),e.fillInStackTrace());
                    }
                    return db;
                }catch(Exception e){
                    Log.e("Log",e.getMessage(),e.fillInStackTrace());
                    if(db!=null)
                        db.close();
                }
                return db;
            }// End of getWritableDatabase()
    
    
    
    **Inserting  and Retrieving data from database:-**
    
    
    public void insertIntoTable(String[] userName,int[] score)
        {
            SQLiteDatabase db = this.getWritableDatabase();
            ContentValues cv = new ContentValues();
    
            try {
                db.beginTransaction();
                for (int i = 0; i < beatID.length; i++) {
                    cv.put("UserName",userName[i]);
                    cv.put("Score",score[i]);
    
                    db.insert("TableName", "UserName",
                            cv);
                }
                db.setTransactionSuccessful();
            } catch (Exception ex) {
    
            } finally {
                db.endTransaction();
                db.close();
            }
        }
    
    
    public void getUserNamePswd(){
            Cursor c = null;
            SQLiteDatabase db = null;
            try{
                db = this.getReadableDatabase();     
                c = db.rawQuery("Select UserName,Score from TableName",null);
                c.moveToFirst();
                String[] username = new String[c.getCount()];
                int[] score = new int[c.getCount()];            
                int counter = 0;
                c.moveToFirst();
                while(!c.isAfterLast()){
                username[counter] = c.getString(0);
                score[counter] = c.getInt(1);
                c.moveToNext();
                counter++;
                }
    
    
            }catch(Exception e){
                Log.e("Log", e.getMessage(), e.fillInStackTrace());
                return null;      
            }finally{
                c.close();
                db.close();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get data pulled from a SQLite file, i have created
Is it possible to read an .SQL file that is created from an SQLite
I have created a Python module that creates and populates several SQLite tables. Now,
I have created a SQLite database from Java. Now I want to know where
I have created a file named MyFile.db using SQLite3 from my C#.net application. This
I have installed SQLite and am using the wrapper from: http://sqlite.phxsoftware.com/ I have created
I have a sqlite DB created by my CoreData model automatically, but my app
I have an XML file containing seed data that I'm trying to load into
I have created a c++ program but now I need to store on the
I just created a new SQLite database from the command line and I have

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.