I have a huge Database. And i want to save it in the Assets folder and read the data from it.
How i can do this?. I read many answers but i didn't understand how to do it.
Please, Help me with the full steps. Because i am A beginner
I have a huge Database. And i want to save it in the Assets folder and read the data from it.
How i can do this?. I read many answers but i didn't understand how to do it.
Please, Help me with the full steps. Because i am A beginner
Save your database in
assets/databases/database_name.sqlite
Add this to your build.gradle
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
and sync your app.
Then Create database class:
MyDatabase.java
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
public class MyDatabase extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "database_name.sqlite";
private static final int DATABASE_VERSION = 1;
public MyDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}
Then access your database like this where you want:
MyDatabase myDatabase = new MyDatabase(context);
SQLiteDatabase db = myDatabase.getReadableDatabase();