-3

I have an app with a database and data in it, and when I tried passing my app to another phone the data is gone. What should be the problem any advice or something that can help?

This is my code in creating my database

public class DbDialect {

public static final String KEY_ROWID = "_id";
public static final String KEY_TAGALOG = "tagalog";
public static final String KEY_BICOLANO = "bicolano";
public static final String KEY_ILOCANO = "ilocano";

private static final String DATABASE_NAME = "Dialectsdb";
private static final String DATABASE_TABLE = "dialectsTable";
private static final int DATABASE_VERSION = 3;

private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;


private static class DbHelper extends SQLiteOpenHelper{

    public DbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
                KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_TAGALOG + " TEXT NOT NULL, " + KEY_BICOLANO +
                " TEXT NOT NULL, " + KEY_ILOCANO +" TEXT NOT NULL );"   
        );

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_NAME + "");
        onCreate(db);

    }

}

public DbDialect(Context c){
    ourContext = c;

}


public DbDialect open() throws SQLException{
    ourHelper = new DbHelper(ourContext);
    ourDatabase = ourHelper.getWritableDatabase();
    return this;
}

public void close(){
    ourHelper.close();
}

public long createEntry(String tagalog, String bicolano, String ilocano) {
    // TODO Auto-generated method stub
    ContentValues cv = new ContentValues();
    cv.put(KEY_TAGALOG, name);
    cv.put(KEY_BICOLANO, hotness);
    cv.put(KEY_ILOCANO, surname);
    return ourDatabase.insert(DATABASE_TABLE, null, cv);


}
public String getData() {
    // TODO Auto-generated method stub
    String[] columns = new String[]{ KEY_ROWID, KEY_TAGALOG, KEY_BICOLANO, KEY_ILOCANO};
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
    String result = "";

    int iRow = c.getColumnIndex(KEY_ROWID);
    int iTagalog = c.getColumnIndex(KEY_TAGALOG);
    int iBicolano= c.getColumnIndex(KEY_BICOLANO);
    int iIlocano= c.getColumnIndex(KEY_ILOCANO);

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
        result = result + c.getString(iRow) + " " + c.getString(iName) + " " + c.getString(iHotness) + " " + c.getString(iSurname) + "\n";
    }
    return result;
}


public String getTagalog(String s) {
    // TODO Auto-generated method stub
    Cursor c = ourDatabase.rawQuery("SELECT * FROM " + DATABASE_TABLE + " WHERE " + KEY_TAGALOG + " LIKE '" + s + "' OR " + 
    KEY_BICOLANO + " LIKE '" + s + "' OR " + KEY_ILOCANO + " LIKE '" + s + "'", null);

    //SELECT * FROM a WHERE tagalog LIKE "Wala" OR bicolano LIKE "Dai" OR ilocano LIKE "Wara"

    if (c != null){
        c.moveToFirst();
        String Tag = c.getString(1);
        return Tag;
    }
    return null;
}


public String getBicol(String s) {
    // TODO Auto-generated method stub
    Cursor c = ourDatabase.rawQuery("SELECT * FROM " + DATABASE_TABLE + " WHERE " + KEY_TAGALOG + " LIKE '" + s + "' OR " + 
            KEY_BICOLANO + " LIKE '" + s + "' OR " + KEY_ILOCANO + " LIKE '" + s + "'", null);
    if (c != null){
        c.moveToFirst();
        String Bic = c.getString(2);
        return Bic;

    }

    return null;
}


public String getIlocano(String s) {
    // TODO Auto-generated method stub
    Cursor c = ourDatabase.rawQuery("SELECT * FROM " + DATABASE_TABLE + " WHERE " + KEY_TAGALOG + " LIKE '" + s + "' OR " + 
            KEY_BICOLANO + " LIKE '" + s + "' OR " + KEY_ILOCANO + " LIKE '" + s + "'", null);
    if (c != null){
        c.moveToFirst();
        String Bic = c.getString(3);
        return Bic;
    }
    return null;
}

}

  • is this a question about programming? You have to be more specific, show what You have done, post some code. Where is the database saved, how did You "pass" Your app to another phone etc.... – Opiatefuchs Jan 28 '15 at 11:46
  • Sorry may I'm new here. I'll try to edit my post. – Hugo Estepa Ü Jan 28 '15 at 12:35
  • I passed my app through app sharer application – Hugo Estepa Ü Jan 28 '15 at 12:36
  • ok, so it is not possible to share the database with an application like this. You can share this only with some root tools, where You can go the App internal storage. – Opiatefuchs Jan 28 '15 at 12:59
  • It seems like I know what is the problem could it be that I do not have a concrete database. because I searched it in my device and there is no database or file that has the value? – Hugo Estepa Ü Jan 28 '15 at 14:51
  • what possibly will work is, if You have a static database, where nothing get changed, I mean, where You only want to get some data from, You can place it into the raw folder and then, copy it inside a method in Your app to the internal folder. But there is no other possibility, an internal saved database could not be transmitted/copied. – Opiatefuchs Jan 28 '15 at 14:56
  • It doesn´t matter if You have no database file in Your app storage folder. I think You have just not created it now, but also if You had one, it will be not possible. – Opiatefuchs Jan 28 '15 at 14:57

1 Answers1

2

YOUR database stores ONLY in your phone. The data cannot be copied when you setup your app on other device (if you don't export app data some way).

anil
  • 2,083
  • 21
  • 37