Database inside of Android - android

I wonder whether there is a way to store data in like a MySQL inside of Android OS.
I have more complex data that I need to save and I dont think SharedPreferences will work.
Is there a predefined way, and how can I access it? Is it in SQL?

Of course there is. On Android each application has own place for database (SQLite). Read http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
for further details. It's really easy to maintain

Yep, there is SQLite
Here is a question asking for examples.
Here is the SQLiteDatabase class. Goo start point.

well there is SQLite database which is very light weight database to store data in android..
Edit
when you start working with SQLite on android you should not mix it up with MySQL or PHPMyAdmin or any other complex database structure. SQLite is just about storing some information on your device internally and accessing it for some purpose. It is not used for complex database tasks that you do in PhpMyAdmin.
Rather you should visit the links given by #Vee in the answer.

Related

Using the same database in all activities Android SQLite

i am new to android. i already created a database and store some data there. What i want is that the stored data in my database, I want to print it all out in another activity.
I don't know how to do this sharing of one database in all activities. I did research but they are all complex codes that i don't understand. Greatly appreciated if you could give me some simple codes about it. Thanks
im using SQLLite database.
You can use the same database throughout the whole app. In order to create an interaction bridge between your Activity and Database, you need to utilise few classes like ContentResolver and ContentProvider. Here is android example of how to create a ContentProvider -
Creating ContentProvider
You can also read this blog for better understanding about how things work in Android in terms of Database.
Hope it helps.
The same database can be used in all activities.You need to create a class through which you can access the database.Before I can tell you how to retrieve data you need to tell me somethings.You have written that you have already created a database.Have you created an external database and are trying use the database from assets folder or have you created an internal database in your android application?

How to use SQL Database other means of Data Storage

I have a SQL Database containing 24 Columns and about 24000 Rows. I want to retrieve data from that SQL Database. I am new to Android and don't know how to use it.
I found an Android library called Realm but I couldn't find a way of Converting SQL to Realm Database.
If there is a simple way to read data from and to store data in SQL Database or another way of storing data in Android in form of Database, please let me know.Any Help will be appreciated.
Thanks!!
android uses SQLite. This is very similar to SQL. You would only need to have the app download the data from the server database and copy in into the local database.
SQLite information can be found at http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
Converting from an SQL file has been discussed at Convert MySQL to SQlite
Android comes with SQLite, this is what you should use. did you search anything like "Android and sql"? android training on the subject
Edit:
so you dont have an sql file, you have an online MySql database. can use jdbc but it is not widely recomended. there are some alternatives as in here and here
Not sure if this will help, but . . .
I have been playing around with different programming options for my Android tablet. One is RFO Basic! freely available from the Google store. It seems to be a dialect of Dartmouth Basic with a lot of built-in hooks to Android specific functions (GPS, camera, etc) as well as an interface to SQL. The set of example programs that comes with the distribution includes and SQL example.
Being a Basic-language environment it will (1) be easy to learn but (2) probably slow (very slow) on a 24000 row table..
Hope this helps

Manage huge data to insert into sqlite database for an android app

i,m making an android app which deals with counter information of bus train and plain in Bangladesh. I want to store those information into sqlite database. But i can't figure it out what will be the best approach to store those huge amount of info in a tabular form. I mean m i need to code all the data into my src file? OR is there any graphical UI (like MySql database) of this database to write the data into table without coding it?
i don't sure that you understand my question. If you not then please ask what point i make confusion. Advance thanks for helping :)
But i can't figure it out what will be the best approach to store those huge amount of info in a tabular form
SQLite
I mean m i need to code all the data into my src file?
Usually, you'd use an existing API to read the data you want from an existing database somewhere (in this case, often the transport department), and then programmatically iterate over it and store it locally
OR is there any graphical UI (like MySql database) of this database to write the data into table without coding it?
MySQL is not a graphical program. It is a database. You get various graphical interfaces for it, but on its own it isn't one.
MySQL doesn't work on Android
You can write a simple script or app easily enough to allow you to enter the data using a UI

Using Rest to store data in Sqlite

I'm creating my first android app that will make use of SQlite. I have zero experience with databases, except for creating a mysql database to use with wordpress...
Edit: After doing some research about rest, I'm still confused about how rest, sqlite, and android dev fit together. My goal is to access a rest-based web service through a url and access certain datasets, then store them in my SQlite database. Then I want to access the contents of the database through my java program, and use them accordingly.
The datasets can be downloaded individually in CSV format, but because I will be using so many of them, I don't want to go through every line individually and store them in the database. I'm hoping there's a more efficient way to store these datasets in the database.
My main questions are:
How can I copy the XML contents of a webpage from a url into my sqlite database? Can I do this with my java program, through the sqlite database, or a java library?
Do I only need to copy the contents of the webpages from the url into the sqlite database one time? If so, what can I do if any information is changed in the datasets?
You first need a schema for your sqllite DB. That schema should map to the objects behind the web service. For e.g, you need a Person table in your DB if there is a Person entity on the web. It depends on what all you want to capture.
When you are done designing the schema, you should start writing the code that help you create & manage DB on android. This is done with the help of SQLiteOpenHelper class:
http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
If you need to keep the DB synce'd with the data on the cloud (web services), you should implement sync. Android provides a very efficient sync framework.
Also, do watch this video from Android engineers explaining the best practices: http://www.youtube.com/watch?v=xHXn3Kg2IQE
Note, to actually fetch the data from the web service you would use UrlConnection API:
http://developer.android.com/reference/java/net/URLConnection.html
This sample probably captures most of it.
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
In terms of reading CSV files, there are some good resources here:
Can you recommend a Java library for reading (and possibly writing) CSV files?
Once you have read each CSV line into an object, then you can turn around and persist it to the database. I'm the author of ORMLite so I'll talk about using it. I don't believe there is a hibernate port for Android.
There are a number of Android examples to help you to get up to speed with ORMLite. Also some good tutorials. If you want to write a number of rows at once then I'd recommend using the batch tasks ORMLite feature. For information, see the discussion about creating lists of objects on the mailing list.
I can answer your first question about " I'm not sure how to add them efficiently"?
yes, SQlite is very powerful and intelligent, you can add thousand of records in one transaction, just like traditional database, It significantly improve performance.
about second question, as my understanding, because CVS file is very simple, so you can download and analyze it by yourself.

Can I use MySQL with Android or do I have to use SQLite?

When using a database for an Android application, is it possible to use a MySQL database, or do you have to use SQLite?
What I'm trying to do is make an app that allows users to see events on a map. These events are updated by admin staff from the office from a Java-based application that works with the MySQL database.
SqLite is present on the phone with some good tutorials out there to get you started using it.
Check the online docs for more details, and I suggest taking a look at the notepad sample, it will get you up to speed in no time.
http://developer.android.com/guide/topics/data/data-storage.html#db
As far as I know you have to use sqlite. MySQL needs a server which would mean you'd need a locally hosted mysql server on a phone which is going a bit overboard.
you have to use sqlite for your android side database
The best is to use content providers if you want to share information. Android provides built in interface for sqlite (android.database.sqlite) and so sqlite is easiest to use.
Another alternative to Sqlite is Berkeley DB for Android (Berkeley DB - Java Edition)

Categories

Resources