访问随Sqlite数据库浏览器一起提供的Sqlite数据库

时间:2014-02-15 11:05:15

标签: android sqlite

我在Android Project文件夹中复制了数据库并且工作正常。现在,我在表中插入值。所以我想知道,无论如何,我可以使用SqlLite数据库浏览器查看这些数据了。

资产文件夹中的数据库,我打开它但我看不到任何新数据。

我的代码插入数据:,它工作正常,没有错误。

public boolean SaveUserResponse(String QId, String OptionId,
            String ResponseDate) {
        try {
            ContentValues cv = new ContentValues();
            cv.put("QId", QId);
            cv.put("OptionId", OptionId);
            cv.put("ResponseDate", ResponseDate);

            mDb.insert("tblUserResponse", null, cv);

            Log.d("SaveUserResponse", "User Response has been Saved.");
            return true;

        } catch (Exception ex) {
            Log.d("SaveUserResponse", ex.toString());
            return false;
        }

1 个答案:

答案 0 :(得分:0)

您可以使用DDMS从设备中获取数据库(可在android-sdk\tools下找到)。打开Device - > File Explorer。然后导航到data\data\your_app并将数据库拉到磁盘。

顺便说一下,您的数据库不应该放在资产下面,这里有一个代码如何从资产中复制它(您可以在应用程序的第一次运行时调用它):

void copyDataBase() throws IOException {

    String DB_PATH = "/data/data/<app>/databases/";
    String DB_NAME = "db.sqlite";

    //Open your local db as the input stream
    InputStream myInput = myContext.getAssets().open(DB_NAME);
    // Path to the just created empty db
    String outFileName = DB_PATH + DB_NAME;
    //Open the empty db as the output stream
    OutputStream myOutput = new FileOutputStream(outFileName);
    //transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
        myOutput.write(buffer, 0, length);
    }
    //Close the streams
    myOutput.flush();
    myOutput.close();
    myInput.close();
}
相关问题