使用Sqlite从Android中的另一个数据库复制一个数据库

时间:2013-02-26 07:41:52

标签: android android-sqlite

我想将数据库A中的表中的一些列复制到数据库B中的表中。我使用以下代码但它会输出错误消息“OldDB.ACC表不存在”。我该如何纠正?谢谢!

顺便说一下,我将数据库B(OldDB)放入DDMS / data / data / project name / databases

谢谢!

public class DB {


private static final String TAG = "NotesDbAdapter";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;

private static final String DATABASE_CREATE_ACC = "create table ACC "
        + "(_id integer primary key autoincrement, "
        + "Phone text, Name text, " + "MemID text, Smscode text, "
        + "RegDate text, Device text);";

private static final String DATABASE_NAME = "Db";

private static final String DATABASE_TABLE_ACC = "ACC";

private static final int DATABASE_VERSION = 1;

private final Context mCtx;

private static class DatabaseHelper extends SQLiteOpenHelper {

    DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    // create the database if there is no database
    // database stored inside the application
    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(DATABASE_CREATE_ACC);

        String str = "INSERT INTO " + DATABASE_TABLE_ACC + " (Phone) SELECT Phone FROM OldDB.ACC";
        db.execSQL(str);

    }

0 个答案:

没有答案