How to put my DB SQLite in Android app? - android

Hello everyone first of all.
I am making an application for android, which I need to have a database for information.
The database management computer mailbox.
What I need is to take that database and included in the application for android'S SELECT generally.
I've been testing it on this website, but I can not get it to work. I do not think either the DB copy to memory, and then to perform the query, she says she can not find the table.
I have been debugged and saw that even the open works, but something strange happens ...
If you have some method or way of doing this, I would really appreciate it.
Thanks for everything.

Check out these resources
This tutorial by Lars Vogel
This reference article from Android website

Puit it in your assets directory in your apk, and on first use copy to "/data/data/YOUR_PACKAGE/databases/" directory. Here is SO discussion on this topic. database in assets folder

Related

How to work with sqlite DataBase in Xamarin Android?

I searched for along time for how can I use a pre made Excel table, as a reading database in Xamarin.Android.
Of course I can't use it directly, so I tried many different ways. For example, convert to Json, upload to Firebase, and later download it, while the program runs, and fill the sqlite. This way is not effective aadn most of the time doesn't work.
Is there any chance, that someone could please explain or even give a tutorial on how to create sqlite database and work with it directly? If there any other worse or better ways to do it, please tell me.
Thank You!
If you want use sqlite DataBase for Xamarin.Android, you could use sqlite-net-pcl.
Install from NuGet: sqlite-net-pcl
You could cgeck the MS docs from the link below for reference. https://learn.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm

Using Existing sqlite Database with android ADT

I am developing an app in android which consists of activities that need to connect to the Database. I am having an existing sqlite DB with me. But I don't know how to include it in my project. This might be a very basic question, but as I am a newbie, I am finding it quite complex to get it working. Any help would be appreciated.
The easiest solution, by far, is to use SQLiteAssetHelper. You add one JAR to your project, package your database in a ZIP file in a specified location in your project's assets/ directory, then use SQLiteAssetHelper to access your database (much like you would use SQLiteOpenHelper).
try to read more about making a DatabaseHelper extension class
this really helped me during my first database driven app
http://www.codeproject.com/Articles/119293/Using-SQLite-Database-with-Android
The name of this feature of transfer database in android called database Ship.
I have already complete database shipUsing your own SQLite database in Android applications
Also you can see this Stackoverflow Answer

How to use SQLite - Android

Hello
I'm working on an android program that uses a database. My database is going include about 300 to 400 records.
My question is what is be best way to work with the database.
Should I create the database at run time via code and insert the records "manually" every time the program starts, or should I use an external database, that's located in the /assetes folder of the program?
If the second option is the way to go, could someone please give me an advice on how to do that, because I can't find any toturial that covers this subject.
Thank you!
There's another option, which is to initialize the database the first time the program is launched. See the SQLiteOpenHelper class, and especially the onCreate method in that class.
Here is a tutorial for the 2nd option you mentioned.
Put your db in the asset folder and if DB does not exist in /data/data/YOUR_PACKAGE/databases/, it will copy the database over.

Looking for a BackupAgent (for a sqlite database) example

I see several examples here, but none speak to backing up SQLite databases specifically, does anyone have a sample of doing this?
http://www.microdu.com/docs/guide/topics/data/backup.html
You may want to try this question which gives an answer on how to backup your SQLite database so that it will be restored if someone installs it on a new phone (using Google's BackupAgent).
On the other hand, if you want to backup the database yourself, then you could copy it to your SD card as seen done in this question.

Android and fairly large SQLite datafiles

I'm starting an Android project, a port from an existing iPhone project I've completed.
I have a fairly large read-only SQLite database, about 100Mb in all. It's called "mydata.sqlite". Where do I place this in my Eclipse workspace? It's too big for "assets".
Next, how do I best get at the file? I would think to try (handling exceptions later) something like:
SQLiteDatabase myDatabase = null;
myDatabase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
But I would then need the path string myPath and since I don't know where to put the resource I don't know what this needs to be.
Can I put "mydata.sqlite" into "res/raw" (once I create "raw" in Eclipse?) and then reference it as a resource with "R.raw.mydata"?
I would very much appreciate some direct help here, rather than a reference to a tutorial. I have checked tons of these, including those that are already cited here on stackoverflow. I've also gone through the "Notepad" project in the Android developer documents. However these and the documentation typically consider only new, empty or small databases that aren't always persistent. This should be a simple thing and given the time I've spent already it is perhaps easier to ask.
Thanking you kindly in advance for your assistance.
Note that if you are putting a 100MB asset in your .apk, you are going to end up with an app that is too big to publish on Market.
I've never tried to include such a big DB in my app before.
One solution to your question might be renaming your mydata.sqlite to something like mydata.jpg to avoid the file from being compressed by aapt, which after you can put it in asset folder and access it from there.
Any compressed asset file with
an uncompressed size of over 1 MB
cannot be read from the APK.
[source]
Edit: Seems like your best bet now is to retrieve the data in small chunk off a web server when needed? Found this, check out mjc147's solution and Romain Guy from Google explains about the 1mb limitation.
I did it once with a 35MB SQLite database. What I did:
1.) I used a Windows Tool (I think it was TotalCommander) to split that *.db file into pieces of 1MB.
2.) I've put them in the assets folder.
3.) In my database helper class I moved these pieces together during first startup.
It worked perfect and was fast enough.
What you should think about:
1.) At one point you have 3* 50MB during startup on the internal storage so please consider using SD card for your database.
2.) At one point during update of your apps you have 4* 50MB on your device...
Regards
hjw

Categories

Resources