Android数据库超过1MB

时间:2011-08-01 12:04:04

标签: android sqlite

我已经编写了数据库副本。我已将我的数据库放入资产forder.My数据库大小为4.5 MB。 如何分组数据库。

    package com.xont.db;

  public class DataBaseMasterHelper extends SQLiteOpenHelper {

// The Android's default system path of your application database.
private static String DB_PATH = "/data/data/com.xont.controller/databases/";
private static String DB_NAME = "masterventura.db";
private SQLiteDatabase ventura;
private  Context myContext;
private DataBaseHelper myDbHelper;

public DataBaseMasterHelper(Context context) {
    super(context, DB_NAME, null, 1);
    this.myContext = context;
}

/**
 * Creates a empty database on the system and rewrites it with your own
 * database.
 **/
public void createDataBase() throws IOException {
    boolean dbExist = checkDataBase();
    if (dbExist) {
    } else {
        this.getReadableDatabase();
        //this.getReadableDatabase().getPath();
        System.out.println( " ===== " +     this.getReadableDatabase().getPath());
        try {
            copyDataBase();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

public boolean checkDataBase() {
    SQLiteDatabase checkDB = null;
    try {
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null,SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) {
        e.printStackTrace();
    }

    if (checkDB != null) {
        checkDB.close();
    }

    return checkDB != null ? true : false;
}

private void copyDataBase() throws IOException {
    InputStream myInput = myContext.getAssets().open(DB_NAME);
    String outFileName = DB_PATH + DB_NAME;
    OutputStream myOutput = new FileOutputStream(outFileName);
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
        myOutput.write(buffer, 0, length);
    }
    myOutput.flush();
    myOutput.close();
    myInput.close();


}

public void openDataBase() throws SQLException {
    String myPath = DB_PATH + DB_NAME;
    ventura = SQLiteDatabase.openDatabase(myPath, null,SQLiteDatabase.OPEN_READONLY);

}

@Override
public synchronized void close() {
    if (ventura != null)
        super.close();
        ventura.close();
}

@Override
public void onCreate(SQLiteDatabase db) {
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}

}

在copyDataBase()方法中我需要更改代码。如何拆分数据库。请帮我解决这个问题

提前致谢...

1 个答案:

答案 0 :(得分:1)