Jeffery
Jeffery

Reputation: 21

How to interact with sqlite3 in command line on Android application?

I see Android terminal has a function, we can use sqlite3 and interact with it and modify my database.

I try to use Runtime().getRuntime().exec("sqlite3 mydb.db") to open mydb.db, but only what I can do is to insert and delete some data. That is not what I want to do. I want to select some information from mydb.db and I can get those information and show it in my EditText.

Upvotes: 2

Views: 7280

Answers (4)

Avi Kumar
Avi Kumar

Reputation: 4433

To intercat with sqlite through  command prompt 

use following commands


C:\> adb shell 

then

# sqlite3 /data/data/your_package_name/databases/databasename 

to see which table are created under it 

sqlite > .tables

and .help for instructions 

use can see this answer also

Check if the database has been created on Android

Links for tutorials

http://www.higherpass.com/Android/Tutorials/Accessing-Data-With-Android-Cursors/1/

http://www.anotherandroidblog.com/2010/08/04/android-database-tutorial/**

Upvotes: 1

kdehairy
kdehairy

Reputation: 2730

  • you can do a SELECT on sqlite on the command line but then the output will be (by default) directed to the standard output stream. so you can't catch it directly inside your program.
  • you can configure sqlite3 to output to a file by using the command .output FILENAME inside the sqlite3 prompt. then read the output file in your program.

Upvotes: 1

Bruce
Bruce

Reputation: 7132

Android ships the sqlite3 executable for debugging purposes.

From the code, you should use the java primitives, as describes here

You can check examples from the sdk, I think "Contact Manager" is showing it off.

Upvotes: 2

Vishwanath.M
Vishwanath.M

Reputation: 6317

you can use a adb shell in windows

 C:\Program Files\Android\android-sdk\platform-tools>adb shell sqlite3
    SQLite version 3.7.4
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite>

Upvotes: 1

Related Questions