How to insert a database into an Android application - android

I have created a database which contains 4 tables using Firefox plugin. The format of the saved database is .sqlite(name.sqlite).
I just want to know how/where to insert it into the android project that I am developing and what the changes are that I should make in my project (like changes in the Manifest file). I guess I should paste it into an asset folder, but I do not know how to access it in the code.
I want to add, view, update and delete data in the table, how should Ido this? Or Should I use another way?

This is a pretty solid tutorial: http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
Basically, don't copy your sqlite file directly into the project. Follow the steps and create / upgrade your database in the provided onCreate and onUpgrade hooks.
These hooks give you the opportunity to change your database structure when publishing updates through the Play Store.
And the proper places to do longer running operations to upgrade all your data, or prefill your data from disk/network.
If you want to prefill your DB from a dataset, you can provide that data in a raw XML, or JSON, or CSV, and after your onCreate do all the inserts when the app launches from a fresh install.

Here is some good tuts for sqlite...
http://coderzheaven.com/2011/04/using-sqlite-in-android-a-really-simple-example/
http://androidexample.com/SQLite_Database_Manipulation_Class_-_Android_Example/index.php?view=article_discription&aid=51
http://www.vogella.de/articles/AndroidSQLite/article.html

Related

Dragging and Dropping a SQLite database between projects

I see a sqllite database in another application, why can't I just just drag and drop from that application to mine in the eclipse environment? that way I can use data already in that database?
Android doesn't do too well with using an sqlite database file directly. Generally the way to go around it is to package an sqlite database as a resource and on first create of the app to load that resource and then connect to it and then copy all the data out of it. The downside of this is you are essentially doubling all your data.
If you are the publisher of the other app then you can list the database as a shared database to share between your apps.
Share SQLite database between 2 android apps?
Noone has written an Eclipse plugin that does that. You can write one if you feel it is both useful and worth your time.

Android App: can I use iOS sqlite? If not, how do I create a local database from a database in the cloud (Parse.com)?

I am making an Android version of an iOS app that I already have. I want to use a local database so that the user can use most the app offline.
Initally I thought I could use the sqlite database created by Core Data in Xcode, but as I am reading things online it seems like this is not possible. Is this true? Or is there a good way to export it to something Android could use?
If not, I want to create a local database with values from a database on the cloud(I use Parse.com). How can I do this? The data on the cloud doesn't change very often (maybe twice or thrice a year) if that makes any difference.
This is a good tutorial to handle preloaded databases:
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Essentially, once you have your precreated database, put it in your assets directory in your apk. Then on first app use, copy this from assets to "/data/data/YOUR_PACKAGE/databases/" directory.
You have to create the database by code in Android, using a DatabaseHelper http://developer.android.com/guide/topics/data/data-storage.html#db. If you want to use your already created database you will have to export it to SQL statements and then "import" them to your application.

How to store a large number of words (to be accessed by an android app)?

I have a list of words (112,000 in alphabetical order) with one word definitions. The definitions are sometimes more than one and are in the format:
word:definition1|definition2|...
The max number of definitions for a word is 8.
I need a method to store these in a file (or more is okay) so they can be accessed by an android app. Only one word will be accessed at a time. This list will never change.
Considering SQLite, how would I insert the large data into a database?
Considering RandomAccessFile, how would I create a index for these words?
Is there another way?
Thanks.
I would suggest you to go with SQLite as it would be easy to fetch data as and when required and it would be simply easy to get/date/update data from particular position too.
One more benefit is that you can prepare SQLite database by using GUI tool too.
Now follow below procedure to use Existing SQLite database, means that you will have database ready with words data:
Prepare SQLite database same as we do in .NET , here you can prepare it using one of the best tool SQLite Manager which you can download it as a tool/add-on inside Mozilla Firefox.
Once you are done with database, simple paste it inside assets folder.
Now write a code to copy database from assets folder into our app. There are plenty of examples available on web for the same.
Use a sqlite DB , storing 112,000 or more shouldn't be a problem at all for sqlite .
Your can use your db schema something like the following :
And there can be multiple entries of wordId -> meaningId , for each word .
for pre-storing data you could use a tutorial provided by me in my blog : Using Pre-populated sqlite database in android

Browsing Android SQLite database within application

Does anyone know of Android code I could embed directly in my app, such that I could browse my SQLite database directly from within my app?
If not, how about code that reads the SQLite metadata, and dumps table and column names and data to the log? (In JDBC, I'd use databasemetadata to get table info, and then table metadata to get column info...)
I know I can browse on an emulator, and I can copy the db off the device and then point a db browser at it. But this would be a lot more convenient for me during development. This would of course be used only for test databases with tiny amounts of data. Any suggestions?
Have a look at this question: browse data in Android SQLite Database It may not be exactly what you're asking, but may be sufficient for your needs.
Alternatively, there's a sqlite database browser app in the market, which you may be interested in (I haven't tested it myself): https://market.android.com/details?id=com.xuecs.sqlitemanager&hl=en
I think this is what you are looking for .
Using the library in the link below you can browse your app database from your app https://github.com/sanathp/DatabaseManager_For_Android
With this library you can manage your app SQLite database from you app itself.
you can view the tables in your app database , update ,delete, insert rows to your tables .Everything from your app.
Its a single java activity file ,just add the java file to your source folder.When the development is done remove the java file from your src folder thats it .
It helped me a lot .Hope it helps you too .
You can view the 1 minute demo here : http://youtu.be/P5vpaGoBlBY

What kind of database is used in Android document call functions?

Okay, so I am still learning to do some coding here, and I seem to have gotten stuck.
I want to have a select number of documents added to a package for the Android OS
but I don't know how to store said documents. Do I add them all under res/raw, or make an SQLite database and call from there?
More importantly, I need to be able to call those documents when a search criteria is added.
I was on the Android reference site, and they add write functions for the SQLite db, which I would prefer not having as an option.
What kind of database should I implement here?
I would prefer a link to an example, but anything would help at this point.
Try reading this.
Notepad example
or make an SQLlite database and call from there?
No you don't create a SQLlite database it will be created for you after your App start the database call.
See this SQLiteOpenHelper
And SQLiteDatabase

Categories

Resources