1
String gaanaDB = "/data/data/com.xyz/databases/DB";
String converterDB = "/data/data/com.abc/databases/DB";
Runtime.getRuntime().exec("su");
Runtime.getRuntime().exec("busybox cp -f " + gaanaDB + " " + converterDB);

DBhelper.java

package com.aks.gaanaconverter.util;
import android.content.Context; 
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "GaanaDB";
private static final String TABLE_NAME = "table_track_metadata";
private static final String ID = "track_id";
private static final String NAME = "track_name";
private static final String HAS_DOWNLOADED = "has_downloaded";
private static final int HAS_DOWNLOADED_VALUE = 1;

public DBHelper(Context context) {
    super(context, DATABASE_NAME, null, 6);
    // TODO Auto-generated constructor stub
}

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

@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
    // TODO Auto-generated method stub

}

public Cursor getData() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor res = db.rawQuery("select " + ID + "," + NAME + " from "
            + TABLE_NAME/*
                         * +" where "+HAS_DOWNLOADED+"="+HAS_DOWNLOADED_VALUE
                         */, null);
    return res;
}
}

when I try accessing the database it throws no such table found.

I have tried the command in Shell Commander app it works perfect. But when i try to use it in my app it doesnt copy the tables in the database.

Rooted Kitkat and BusyBox installed.

aks
  • 11
  • 2
  • Can you please post the output or the error you are getting? – Jeff Sloyer Apr 15 '15 at 12:27
  • this is the error: android.database.sqlite.SQLiteException: no such table: table_track_metadata (code 1): , while compiling: select track_id,track_name from table_track_metadata – aks Apr 15 '15 at 12:32

1 Answers1

0

Try to create the table first:

 public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE if not exists table_track_metadata(track_id INTEGER PRIMARY KEY AUTOINCREMENT,"
            + "track_name"
            + " TEXT,"...)");

}
Mounir Elfassi
  • 2,242
  • 3
  • 23
  • 38
  • but i am copying that database from other folder then too i need to create it? – aks Apr 15 '15 at 12:38
  • its is creating empty table... but i dont hav my data in it which i m trying to copy using superuser – aks Apr 15 '15 at 12:46
  • which type of file the original database? – Mounir Elfassi Apr 15 '15 at 13:17
  • It is a sqlite db n type i.e. extension is file – aks Apr 15 '15 at 18:52
  • see this answer its perfectly applicable to your case: http://stackoverflow.com/questions/9109438/how-to-use-an-existing-database-with-an-android-application?answertab=votes#tab-top good luck – Mounir Elfassi Apr 15 '15 at 19:32
  • Do check the database string again! Both hav different package names. N streams cannot access files without permissions so i am trying to use superuser – aks Apr 15 '15 at 19:39