我有一个带有数据库和数据的应用程序,当我尝试将我的应用程序传递到另一部手机时数据消失了。什么建议或任何可以帮助的问题应该是什么问题?
这是我创建数据库的代码
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;
}
}
答案 0 :(得分:2)
您的数据库仅存储在手机中。在其他设备上设置应用时,无法复制数据(如果您不以某种方式导出应用数据)。