Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem copying an SQLite database in Android 2.2
    primarykey
    data
    text
    <p>I have to set up 4.55Mb , 2.2Mb two database.we are targeting to 2.2 version.I tried some way, its set up partial file.(3096kb ).If we use API 10 then its working fine.How can I copy to do? How to chunk the file.</p> <p>I tried like this way: </p> <pre><code>private static String DB_PATH = "/data/data/com.android.xont.controller/databases/"; private static String DB_NAME = ""; private SQLiteDatabase ventura; private final Context myContext; // private SQLiteDatabase myDataBase=null; private DataBaseHelper myDbHelper; public DataBaseHelper(Context context, String DB_NAME) { super(context, DB_NAME, null, 1); this.myContext = context; this.DB_NAME = DB_NAME; } /** * Creates a empty database on the system and rewrites it with your own * database. **/ public void createDataBase() throws IOException { boolean dbExist = checkDataBase(); File Path = myContext.getDir("Data", 0); File DBFile = new File(Path, "DEMOUserVentura_HEMA.db"); if (dbExist) { } else { this.getReadableDatabase().close(); //this.getReadableDatabase().getPath(); //System.out.println( " ===== " + this.getReadableDatabase().getPath()); try { copyDataBase(); } catch (IOException e) { throw new Error(e); } } } 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; } private void copyDataBase() throws IOException { //AssetManager am = myContext.getAssets(); //String outFileName = DB_PATH + DB_NAME; // OutputStream os = new FileOutputStream(outFileName); //outFileName.createNewFile(); // byte []b = new byte[1024]; //int i, r; //String []Files = am.list(""); // Arrays.sort(Files); //for(i=1;i&lt;10;i++) //{ // String fn = String.format("%d.db", i); //if(Arrays.binarySearch(Files, fn) &lt; 0) // break; //InputStream is = am.open(fn); // while((r = is.read(b)) != -1) //os.write(b, 0, r); //is.close(); // } // os.close(); // 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)) &gt; 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; ventura = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Override public synchronized void close() { if (ventura != null) ventura.close(); super.close(); } </code></pre> <p>Please provide some solution to this. Please help me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload