2

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.

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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>

Comments

1
  • 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.

3 Comments

Thanks a lot! The first method do not work. I will try the second method soon.
Thank you! I see. I found a solution, that is when I write out and flush SELECT command into sqlite3, I must close this out stream, then I am able to get the output result. But this solution has a shortcoming, if I want to write out another sql command into sqlite3, I will get nothing. So I have to interact with sqlite3 from the beginning. To some degree it looks like After I speak with sqlite3 just one sentence, I have to say goodbye to it, and if I want to say two sentences, I have to speak two times.....
i usually don't ask such questions .. the asker usually knows his problem best .. but .. do you really need to interact with sqlite3 using Runtime? .. if you just want a way to access and manipulate your database, then you can use the android java sdk. it provides a really good and straight forward usage. check this for a starting point SQLiteOpenHelper
1
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/**

2 Comments

Thank you. But I want to interact with sqlite3 in may application not in adb shell command line. We can do those works easily, but how to do it in application is a hard work for me. I want to accomplisth the purpose in my application.
i gave the answer on basis of your question How to interact with sqlite3 in command line on Android application ? i have added two new link , are really good tutorials for database application check them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.