简体   繁体   English

Android如何查看我的SQLite?

[英]Android How can I see my SQLite?

I used Eclipse to open data/data/your.package.name/databases ,but there's nothing in data . 我使用Eclipse打开data/data/your.package.name/databases ,但data没有任何内容。

Some people say I didn't get the "root privileges". 有人说我没有获得“ root特权”。

How can I see my SQLite? 如何查看我的SQLite?

The easiest way, I think, to write a small function in your app, which copies the /data/.../etc to the /sdcard/ , or somewhere else. 我认为,最简单的方法是在您的应用中编写一个小函数,该函数将/data/.../etc复制到/sdcard/或其他位置。

After that, you'll be able, to open that DB from your computer. 之后,您将能够从计算机中打开该数据库。

Here's a full answer, how to copy the file into the SDCard: https://stackoverflow.com/a/19093736/2891426 这是一个完整的答案,如何将文件复制到SDCard: https : //stackoverflow.com/a/19093736/2891426

I would implement this function in a whole new class, and create a button, which calls this. 我将在一个全新的类中实现此功能,并创建一个调用此按钮的按钮。 Or something like this. 或类似的东西。

And you can download a small Windows app from here, to browse the DB file: http://sqlitebrowser.org/ 您可以从此处下载一个小型Windows应用程序,以浏览数据库文件: http : //sqlitebrowser.org/

You do need root access to see the databases on your device. 您确实需要root用户访问权限才能查看设备上的数据库。 You can use an emulator though, instead of the physical device, and that will allow you to explore the databases in Eclipse. 但是,您可以使用仿真器而不是物理设备,这将使您能够在Eclipse中浏览数据库。

you don't need to have root privileges to access external storage. 您无需具有root特权即可访问外部存储。 you need for internal storage though. 但是您需要内部存储。 in eclipse in ddms go to android/data/yourpackage and there you should find all files created by your app. 在ddms的eclipse中,转到android / data / yourpackage,在那里您应该找到您的应用创建的所有文件。 if there is no file, then there is no database. 如果没有文件,则没有数据库。 once you find your database you can use sqliteman to see its content http://sourceforge.net/projects/sqliteman/files 找到数据库后,您可以使用sqliteman查看其内容http://sourceforge.net/projects/sqliteman/files

best solution would be to use internal storage and then just export it to external when you want to access it. 最好的解决方案是使用内部存储,然后在要访问它时将其导出到外部。 look here: https://stackoverflow.com/a/19093736/2026478 看这里: https : //stackoverflow.com/a/19093736/2026478

public void exportDatabse(String databaseName) {
    try {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//"+getPackageName()+"//databases//"+databaseName+"";
            String backupDBPath = "backupname.db";
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

            if (currentDB.exists()) {
                FileChannel src = new FileInputStream(currentDB).getChannel();
                FileChannel dst = new FileOutputStream(backupDB).getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                dst.close();
            }
        }
    } catch (Exception e) {

    }
}

You Should Use SQLiteBrowser For That You can Easily Access Your Database. 您应该使用SQLiteBrowser来轻松访问数据库。 You Can Download from here http://sqlitebrowser.org/ 您可以从此处下载http://sqlitebrowser.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM