Save a database on the sd card

-1

How can I save my database in the sd of my cell phone? Here I have it created:

public class DB extends SQLiteOpenHelper{

String tabla ="CREATE TABLE Datos (Id INTEGER PRIMARY KEY AUTOINCREMENT, N text, C text, R1 INTEGER, R2 INTEGER, R3 INTEGER, P4 text, P5 text)";

public DB(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
    super(context, name, factory, version);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(tabla);
}

@Override
public void onUpgrade(SQLiteDatabase db, int versionAnt, int versionNva) {
    //Se elimina la versión anterior de la tabla
    db.execSQL("DROP TABLE IF EXISTS Datos");

    //Se crea la nueva versión de la tabla
    db.execSQL(tabla);
}

}

    
asked by Pablo Gonzalez 10.03.2017 в 05:26
source

1 answer

0

When you create the database you must enter the path where you want to save it, the path is passed to the super in your constructor through the "name" parameter.

super(context, Environment.getExternalStorageDirectory() + File.separator + FILE_DIR + File.separator + DATABASE_NAME, null, DATABASE_VERSION);
    
answered by 10.03.2017 в 10:24