How can connect Sqlite2009 Pro Database and Android Application
I use Sqlite 2009 pro (Sqlite3 Management Studio) to create new database and insert data. My problem is how can I connect this database and Android application . Whe开发者_如何学Cn installing android application in phone, how can put database with application ?Please help me.
I'm assuming you are creating the database outside of Android. With this method you will simply copy the database to the applications folder (after installing your application), and then you should have it for use.
- Create your database (lets call it mydb.db)
- Install your base Android application (no db)
- Open a command prompt, and cd into the directory with your mydb.db
- Type adb push mydb.db /data/data/com.my.app.myapplication/databases
This copies your database that you created to the proper folder that your application should use for your databases (this is my folder structure on 2.2/2.3). Now in your java class, when you specify the database name, it should be mydb.db.
Generally you want to have all of your creation and update scripts built into your program. Using the Management Studio can be handy at first to design the db, but ultimately you'll want to use SQLiteOpenHelper to handle create/drop/update scripts. See this and this link for help with the SQLiteOpenHelper class.
NOTE: I just realized I am doing this on a rooted device, and you MAY not have access to copy to the /data/data/com.my.app/... folder. If you don't, then you might have to find some writable folder to put your database, and somehow access it. Or just use SQLiteOpenHelper :).
精彩评论