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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:58:01+00:00 2026-06-09T02:58:01+00:00

I have created an sqlite database on a Java application and have pushed it

  • 0

I have created an sqlite database on a Java application and have pushed it to my android. I want to read this database (probably write into it later too). Most of the tutorials I have found so far create the DB within the android…

I don’t think I need to override the onCreate() and onUpdate() methods of SQLiteOpenHelper class do I ? Also the part that in the below tutorial he has created the tables, since I already have my database

Any tutorial, sample code u guys might know of ?

public class DatabaseHandler extends SQLiteOpenHelper {

    // All Static variables
    // Database Version
    private static final int DATABASE_VERSION = 1;

    // Database Name
    private static final String DATABASE_NAME = "contactsManager";

    // Contacts table name
    private static final String TABLE_CONTACTS = "contacts";

    // Contacts Table Columns names
    private static final String KEY_ID = "id";
    private static final String KEY_NAME = "name";
    private static final String KEY_PH_NO = "phone_number";

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

    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
                + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
                + KEY_PH_NO + " TEXT" + ")";
        db.execSQL(CREATE_CONTACTS_TABLE);
    }

    // Upgrading database
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);

        // Create tables again
        onCreate(db);
    }

I Simply need to open the DB I have in the memory, execute an sql query agianst my DB and get the result.

  • 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-09T02:58:02+00:00Added an answer on June 9, 2026 at 2:58 am

    You must copy the db from assets to your apps storage area (or another accessible location) on the device before you can use it. You cannot use it directly out of the .apk file.

    An example of how to go about it:

    public class DBAdapter { 
    
    // DB info 
    public static final String MAIN_DATABASE_NAME = "yourDB"; 
    public static String MAIN_DB_PATH = "/data/data/your.package.name/databases/"; 
    public static final int MAIN_DATABASE_VERSION = 1; 
    
    // database control 
    private DatabaseHelper mDbHelper; 
    private static SQLiteDatabase mDb; 
    private static Context mCtx; 
    
    private static class DatabaseHelper extends SQLiteOpenHelper { 
        DatabaseHelper(Context context, String dbname, int dbversion) { 
            super(context, dbname, null, dbversion); 
            if (checkDataBase(dbname)) { 
                openDataBase(dbname); 
            } else { 
                try { 
                    this.getReadableDatabase(); 
                    copyDataBase(dbname); 
                    this.close(); 
                    openDataBase(dbname); 
                } catch (IOException e) { 
                    throw new Error("Error copying database"); 
                } 
                Toast.makeText(context, 
                        "Initial " + dbname + " database has been created", 
                        Toast.LENGTH_LONG).show(); 
            } 
        } 
    
        @Override 
        public void onCreate(SQLiteDatabase db) { 
        } 
    
        @Override 
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
        } 
    } 
    
    public DBAdapter(Context ctx) { 
        DBAdapter.mCtx = ctx; 
    } 
    
    public DBAdapter open(String dbname, int dbversion) throws SQLException { 
        mDbHelper = new DatabaseHelper(mCtx, dbname, dbversion); 
        mDb = mDbHelper.getWritableDatabase(); 
        return this; 
    } 
    
    public void close() { 
        mDbHelper.close(); 
    } 
    
    private static void copyDataBase(String dbname) throws IOException { 
        InputStream myInput = mCtx.getAssets().open(dbname); 
        String outFileName = MAIN_DB_PATH + dbname; 
        OutputStream myOutput = new FileOutputStream(outFileName); 
        byte[] buffer = new byte[1024]; 
        int length; 
        while ((length = myInput.read(buffer)) > 0) { 
            myOutput.write(buffer, 0, length); 
        } 
        myOutput.flush(); 
        myOutput.close(); 
        myInput.close(); 
    } 
    
    private static boolean checkDataBase(String dbname) { 
        SQLiteDatabase checkDB = null; 
        boolean exist = false; 
        try { 
            String db = MAIN_DB_PATH + dbname; 
            checkDB = SQLiteDatabase.openDatabase(db, null, 
                    SQLiteDatabase.OPEN_READONLY); 
        } catch (SQLiteException e) { 
            Log.v("db log", "database does't exist"); 
        } 
        if (checkDB != null) { 
            exist = true; 
            checkDB.close(); 
        } 
        return exist; 
    } 
    
    private static void openDataBase(String dbname) throws SQLException { 
        String dbPath = MAIN_DB_PATH + dbname; 
        mDb = SQLiteDatabase.openDatabase(dbPath, null, 
                SQLiteDatabase.OPEN_READWRITE); 
    } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a SQLite database from Java. Now I want to know where
I have made this code to open a database(created in SQLite browser) stored in
I have written a java application that sporadically logs events to an SQLite database
I have created a database using SQLite. I want to update the value of
I have a distributed java application and I want to send the database data
I have a sqlite database in my application. I want to make an expandable
I have Created a database in Sqllite Android Application and I tried to add
I am developing an android application in which I have created a database named
I'm working on an application which uses SQLite Database on Android.I have a custom
I want to create a database for my android application. I have written the

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.