Create database from prestored db file on SDcard

↘锁芯ラ 提交于 2019-12-08 11:03:45

问题


The database i want to import is over 5Mb. When i put the .db in asset folder i got some errors. So i split the database into smaller db files and assemble the pieces to create the database. So is there any way i can import the database from sdcard and start using the db without splitting and assembling?

Thanks in advance.


回答1:


Yes, there is: place the database file inside the sdcard then create a method inside a class, the method is like:

public class DB_Path {
    public final SQLiteDatabase getOrders() {
            File dbfile = new File("/sdcard/TheDataBaseFile");
            SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
                 return db;
        }
}
-----------------------

initialize like

public DB_Path dbp = new DB_Path();
    public SQLiteDatabase db = dbp.getOrders();

after that you can call the cursor with db.

  Cursor cur = db.rawQuery("the sql query",null); 


来源:https://stackoverflow.com/questions/10481983/create-database-from-prestored-db-file-on-sdcard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!