Evan
Evan

Reputation: 15

Create database from prestored db file on SDcard

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.

Upvotes: 0

Views: 1159

Answers (1)

DAS
DAS

Reputation: 696

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); 

Upvotes: 1

Related Questions