Skip to content Skip to sidebar Skip to footer

Finding Database Path Is Impossible

I am quite new to android development and right now I'm trying to create a database through a class extending SQLiteOpenHelper. I am positively sure that the data is being stored

Solution 1:

How about setting the dbname as full path:

StringDATABASE_NAME="/data/data/"+packageName+"db.db";

or put your db in SD card:

StringDATABASE_NAME= Environment.getExternalStorageDirectory()+packageName+"db.db";

pass the dbPath in your code:

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

Solution 2:

if you are trying to get database which is stored in applicaiton package from device thn you will not get direct access from device /data/data/app packagename/databases/ ..you can access and modify using helperclass bt direct export nt poss AFAIK ... bt from emulator u cn gt

enter image description here

If you to export database from in sd card from application package

try this

privatevoidcopyFromDataPackgeToSdCard()throws IOException {
    try {
        FilesdCard= Environment.getExternalStorageDirectory();
        FileappDataDir= Environment.getDataDirectory();
        if (sdCard.canWrite()) {
            StringcurrentDBPath="//data//" + getPackageName()
                    + "//databases//"
                    + DatabaseImplementation.DATABASE_NAME;
            StringbackupDBPath= DatabaseImplementation.DATABASE_NAME;
            FilecurrentDatabase=newFile(appDataDir, currentDBPath);
            FilebackupDatabase=newFile(sdCard, backupDBPath);

            if (currentDatabase.exists()) {
                FileChannelsrc=newFileInputStream(currentDatabase)
                        .getChannel();
                FileChanneldst=newFileOutputStream(backupDatabase)
                        .getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                dst.close();
            }
        }
    } catch (Exception e) {
        Log.e("copyFromDataPackgeToSdCard", e.getMessage());
    }
}

Post a Comment for "Finding Database Path Is Impossible"