Home » Android » Android – viewing SQLite databases on device?

Android – viewing SQLite databases on device?

Posted by: admin June 15, 2020 Leave a comment

Questions:

Is there any tool that will allow me to browse databases on my Android device? Something like Sql Management Studio – you know GUI tool that displays databases, tables, row in tables, etc.

I’m using Eclipse for development (if it is important for plug-in suggestions).

Thanks!

How to&Answers:

My suggestion is to run your app on emulator (so you could copy db file right from ADT File Explorer) and then view it with SQLite Manager Firefox plugin.

Answer:

First of all, you will not be able to ‘browse’ the databases unless you logged in as root (there are several tutorials out there that explains how to get root on Android). Secondly, you can use adb shell (adb is included into the SDK), and when you are there you can use the sqlite3 command to browse the databases.

Of course, sqlite3 does not provide a GUI… but, you can copy the database you want to browse to your computer and use any GUI for sqlite there.

Answer:

Yes we can do this but in different way.Using this logic you will get database in SDcard.

        String sourceLocation = "/data/data/com.sample/databases/yourdb.sqlite" ;// Your database path
        String destLocation = "yourdb.sqlite";
        try {
            File sd = Environment.getExternalStorageDirectory();
            if(sd.canWrite()){
                File source=new File(sourceLocation);
                File dest=new File(sd+"/"+destLocation);
                if(!dest.exists()){
                    dest.createNewFile();
                }
                if(source.exists()){
                    InputStream  src=new FileInputStream(source);
                    OutputStream dst=new FileOutputStream(dest);
                    // Copy the bits from instream to outstream
                    byte[] buf = new byte[1024];
                    int len;
                    while ((len = src.read(buf)) > 0) {
                        dst.write(buf, 0, len);
                    }
                    src.close();
                    dst.close();
                }
            }
            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }

You have to give permission

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Answer:

You can download a plugin “com.questoid.sqlitebrowser_1.2.0″….Just pop it in google and download it. From the drop it on to the eclipse running folder, under the plugins folders.
When you run the app on the emulator, you will be able to view all the database information on the DDMS section.