Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - viewing SQLite databases on device?

Tags:

android

sqlite

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!

like image 393
nikib3ro Avatar asked May 20 '10 20:05

nikib3ro


People also ask

How can I see all SQLite databases?

To show all databases in the current connection, you use the . databases command. The . databases command displays at least one database with the name: main .

Where is the SQLite database stored in Android?

The Android SDK provides dedicated APIs that allow developers to use SQLite databases in their applications. The SQLite files are generally stored on the internal storage under /data/data/<packageName>/databases.

How do I view a SQLite database in my browser?

a) On Windows, From the View menu item select 'preferences' and select the Data Browser tab. b) On Mac, From the “DB Browser for SQLite” menu item select 'preferences' and select the Data Browser tab.


2 Answers

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.

like image 135
Cristian Avatar answered Nov 11 '22 13:11

Cristian


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" />
like image 32
Parag Chauhan Avatar answered Nov 11 '22 12:11

Parag Chauhan