android - Saving database to SDcard -


i'm trying save sqlite database sd card.i tried couple of things couldn't figure out , gave me errors,for example couldn't find table though creating database on sd card. ended deleting everything...

what need add or change save sd card ? make clear,i'm not trying copy sd card,i'm trying save on sd card instead of internal storage.

here's database far.

public class backup_db extends sqliteopenhelper { private static final string db_name = "backup.db"; private static final int db_version_number = 1; private static final string db_table_name = "backup"; private static final string tag = "countriesdbadapter"; private final context mctx; private backup_db mdbhelper; public static final string key_rowid = "_id"; static final string db_column_1_name = "country_name";  static final string db_column_3_name = "country_price";  private static final string db_create_script = "create table "         + db_table_name         + " ( _id integer primary key autoincrement,country_name text unique,country_price real)";  private sqlitedatabase sqlitedbbackup = null;  public backup_db(context context) {     super(context, db_name, null, db_version_number);     this.mctx = context; }  public backup_db open() throws sqlexception {     mdbhelper = new backup_db(mctx);     sqlitedbbackup = mdbhelper.getwritabledatabase();     return this; }  @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {     // todo: implement onupgrade  }  @override public void oncreate(sqlitedatabase sqlitedbbackup) {     log.i("oncreate", "creating database...");     sqlitedbbackup.execsql(db_create_script); }  public void opendb() throws sqlexception {     log.i("opendb", "checking sqlitedbbackup...");     if (this.sqlitedbbackup == null) {         log.i("opendb", "creating sqlitedbbackup...");         this.sqlitedbbackup = this.getwritabledatabase();      } }  public void closedb() {     if (this.sqlitedbbackup != null) {         if (this.sqlitedbbackup.isopen())             this.sqlitedbbackup.close();     } }  public void insertcountry(string countryname, string countryprice) {      sqlitedbbackup.execsql("insert or ignore " + db_table_name             + "(country_name) values('" + countryname + "')");      sqlitedbbackup.execsql("update " + db_table_name             + " set country_price=" + countryprice             + " country_name='" + countryname + "';"); } 

sqliteopenhelper isn't built creating external database. in sqliteopenhelper construtor, context passed in , used create files in package folder. have @ source code sqliteopenhelper . can create in internal first, exporting it. remember add permissions.

try helper class wrote dbassethelper

export:

new assetdatabasehelper(this,"test.sqlite").exportdatabase("/flder_toexport/canberenamedhere.sqlite"); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -