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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:23:28+00:00 2026-06-12T07:23:28+00:00

I created my own database for my project, but i am having a trouble

  • 0

I created my own database for my project, but i am having a trouble pushing it in the data/data folder.
I first tested it out on my rooted phone and i successfully pushed the database that i created.
Now im facing a problem on testing it on a different phone. i get an error

android.database.sqlite.SQLiteException: no such table: tblFirstAid: , while compiling: SELECT faName FROM tblFirstAid

I placed my database in the assets folder and it was running fine on my rooted phone.
What code would i add for it to copy the file from the assets folder and push it inside the /data/data directory.
I already tried the one reigndesign and I am getting that error.

Here is my DB Helper Class

package com.dr.droid.lee;

import java.io.IOException;
import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.http.SslCertificate.DName;
import android.util.Log;

public class DbHelper {

    public static final String Row_id = "_id";
    public static final String Row_Name = "faName";
    public static final String Row_Desc = "faInfo";
    private static final String db_Name = "dbDrDroid";
    private static final String db_Table = "tblFirstAid";
    private static final String db_HTable = "tblHospitals";
    private static final String Row_HosName = "HospitalName";
    private static final String Row_HosAdd = "Address";
    private static final String Row_HosReg = "Region";
    private static final String Row_HosCity = "City";
    private static final String Row_HosContact = "Contact";
    private static final String Row_dName = "dName";
    private static final String Row_dTable = "tblDisease";
    private static final int db_Version = 1;
    private dbhelp ourhelper;
    private static Context ourcontext;
    private SQLiteDatabase ourDB;

    private static class dbhelp extends SQLiteOpenHelper{

        public dbhelp(Context context) {
            super(context, db_Name, null, db_Version);
            // TODO Auto-generated constructor stub
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub



            db.execSQL("CREATE TABLE IF NOT EXISTS " + db_Table + " (" + Row_id + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                + Row_Name + " TEXT NOT NULL, "
                + Row_Desc + " TEXT NOT NULL)" );

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub
            db.execSQL("DROP TABLE IF EXISTS" + db_Table);
            onCreate(db);

        }

    }

    public DbHelper (Context c){
        ourcontext= c;
    }

    public DbHelper open(){
        ourhelper = new dbhelp(ourcontext);
        ourDB = ourhelper.getWritableDatabase();
        return this;
    }

    public void   close(){
        ourhelper.close();
    }

    public ArrayList<String> getFAData() {
        // TODO Auto-generated method stub
        ArrayList<String> comments = new ArrayList<String>();
        String [] columns = new String[]{Row_Name};
        Cursor c = ourDB.query(db_Table, columns, null, null, null, null, null);
        int iRow = c.getColumnIndex(Row_Name);
        c.moveToFirst();
        while (!c.isAfterLast()) {          
            comments.add(c.getString(iRow));
            c.moveToNext();
        }

        c.close();
        return comments;
    }

    public ArrayList<String> getHData(){
        ArrayList<String>  res = new  ArrayList<String>();
        String [] columns = new String []{Row_HosName};
        Cursor h = ourDB.query(db_HTable, columns, null, null, null, null, Row_HosName);
        int HRow = h.getColumnIndex(Row_HosName);
        h.moveToFirst();
         while (!h.isAfterLast()) {          
                res.add(h.getString(HRow));
                h.moveToNext();
            }

            h.close();
            return res;

    }

    public ArrayList<String> getDData(){
        ArrayList<String>  res = new  ArrayList<String>();
        String [] columns = new String []{Row_dName};
        Cursor d = ourDB.query(Row_dTable, columns, null, null, null, null, null);
        int HRow = d.getColumnIndex(Row_dName);
        d.moveToFirst();
         while (!d.isAfterLast()) {          
                res.add(d.getString(HRow));
                d.moveToNext();
            }

            d.close();
            return res;

    }



}

Here is the class that i used from reigndesign

package com.dr.droid.lee;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;

public class DataBaseHelper extends SQLiteOpenHelper{

    //The Android's default system path of your application database.
    private static String DB_PATH = "/data/data/com.dr.droid.lee/databases/";

    private static String DB_NAME = "dbDrDroid";

    private SQLiteDatabase myDataBase; 

    private final Context myContext;

    /**
     * Constructor
     * Takes and keeps a reference of the passed context in order to access to the application assets and resources.
     * @param context
     */
    public DataBaseHelper(Context context) {

        super(context, DB_NAME, null, 1);
        this.myContext = context;
    }   

  /**
     * Creates a empty database on the system and rewrites it with your own database.
     * */
    public void createDataBase() throws IOException{

        boolean dbExist = checkDataBase();

        if(dbExist){
            //do nothing - database already exist
        }else{

            //By calling this method and empty database will be created into the default system path
               //of your application so we are gonna be able to overwrite that database with our database.
            this.getReadableDatabase();

            try {
                this.close();
                copyDataBase();

            } catch (IOException e) {

                throw new Error("Error copying database");

            }
        }

    }

    /**
     * Check if the database already exist to avoid re-copying the file each time you open the application.
     * @return true if it exists, false if it doesn't
     */
    private boolean checkDataBase(){

        SQLiteDatabase checkDB = null;

        try{
            String myPath = DB_PATH + DB_NAME;
            checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

        }catch(SQLiteException e){

            //database does't exist yet.

        }

        if(checkDB != null){

            checkDB.close();

        }

        return checkDB != null ? true : false;
    }

    /**
     * Copies your database from your local assets-folder to the just created empty database in the
     * system folder, from where it can be accessed and handled.
     * This is done by transfering bytestream.
     * */
    private void copyDataBase() throws IOException{

        //Open your local db as the input stream
        InputStream myInput = myContext.getAssets().open(DB_NAME);

        // Path to the just created empty db
        String outFileName = DB_PATH + DB_NAME;

        //Open the empty db as the output stream
        OutputStream myOutput = new FileOutputStream(outFileName);

        //transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0){
            myOutput.write(buffer, 0, length);
        }

        //Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();

    }

    public void openDataBase() throws SQLException{

        //Open the database
        String myPath = DB_PATH + DB_NAME;
        myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

    }

    @Override
    public synchronized void close() {

            if(myDataBase != null)
                myDataBase.close();

            super.close();

    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

Some how i am still getting errors if my i don’t push my database in my phone.

  • 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-12T07:23:29+00:00Added an answer on June 12, 2026 at 7:23 am

    I assume that your DB_NAME is not the same to the Database which exists in your assests folder.

    If you are following “reigndesign”, then check this line:

    private static String DB_NAME ="myDBName"; 
    

    DB_NAME here is the name of your database. It is assumed that you have a copy of the database in the assets folder. Your DB_NAME must be the same which exists in the assets folder.

    OR

    Follow this.

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

Sidebar

Related Questions

I've trouble with actionListener. I created own simple dialog, which has only two JButtons
I created my own class but when I try to instantiate it I run
I have a Symfony2 project with its own database, and now I want to
I inherited a project where each 'customer' has its own database. There are hundreds
I'm developing a project that works on remote server database tables. But there were
If I wanted to create my own relational database with a modern language to
I created my own custom date picker consisting of an ASP TextBox, Button, and
I created my own behavior as follows: public class BoundaryExceptionHandlingBehavior : IInterceptionBehavior { public
I've created my own signup form and creating the user using the Membership class.
I have created my own Attached Property like this: public static class LabelExtension {

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.