I am currently developing an application which if I don't have a database, the application after building will be heavy. How do I connect the application to a database, either local or remote?
Thanks in advance.
You can use one of the following methods for using database:
1- Using HTML5 client side databases. HTML5 provides four different types of Storage of data on a local client's machine. They are
Local Storage.
Web SQL Storage.
Session Storage
Indexed DB
It depends on your demands you can use one of them. If you need a persistent database for saving values less than 5 Mb, I recommend you LocalStorage as implementation of that is very easy. The data you saved in HTML5 localstorage will not be deleted even in case of phone shut down or reset. The data will be deleted only when you remove it by localStorage.removeItem(); Client side database is not recommended if you have huge amount of data or you need a central database which you should show to everybody who use this app in the world. in these cases its better, you use server side database
You can read a very nice article about how to use html5 local databases in XDK website:
https://software.intel.com/en-us/articles/html5-local-storage
2- You can use server database like MySQL or SQL server. however you need to connect your html codes to a PHP or asp.net script in a server by AJAX. You may use JSON for transfer data from PHP in server side to JS in the client side.
3- You can use cloud databases like Parse.com however Parse.com will be fully retired on January 28, 2017.
For local storage of a web or hybrid app you can use IndexedDB. There's a great tutorial on HTML5 rocks for a TODO list that you can follow: http://www.html5rocks.com/en/tutorials/indexeddb/todo/.
For remote databases, I like to use Parse.com to store data objects like for games I store user settings, high scores, etc. https://parse.com/docs/rest. Take a look at their Quickstart guide.
Hope that helps!
You could use LOCAL STORAGE the usage is pretty easy:
/* saving the data in Local Storage */
//yourData : this data could be an array, object or a plain string
window.localStorage.setItem('data', JSON.stringify(yourData));
/* retriving the data from local storage */
window.localStorage.getItem('data');
That's all, make sure your data doesn't exceed 5 MB.
Related
I started developing an app that uses sqlite that is to be installed on multiple devices and any updates done on sqlite database from any device are to be reflected in other devices as well. I have researched a little and found that Sqlite DB is local to a device and changes done in one device are not reflected in others and for that I have to use external server. Is there any way around it?
Is it optimal to directly store data in external server or use sqlite and sync it regularly with external database?
Thanks in advance
As far as I know, there isn't a way without an external database. I would recommend you to sync it regularly with an external database.
Checkout this question for more information how to do that:
How to sync SQLite database on Android phone with MySQL database on server?
Answer of Andrew White
Create a webservice (REST is probably best) and serialize your SQLite/MySQL data and PUT/POST/GET it to/from your web service. This will give you a nice layer of abstraction in case you decide to switch from MySQL to something else server side.
You will achieve your goal using external server. It's not necessary to create your own server, just use data store services like Parse. For more look here.
You can use data directly from external server or cache them on your device first (sqlite, prefs, json etc.) – it's up to you.
We are developing an app for both iOS and Android. In both the platforms we are not using the native DB (i.e., in iOS core data and in Android sqlLite). Instead of native DB we are using Parse local datastore.
In Parse we are going to keep huge amounts of static content. When user’s install the app for the first time, we don’t want all the contents from Parse to be downloaded. Because it may take some time to download the contents from DB.
So we have decided to use the seed database concept. This will not take much time. It will be a good user experience.
Our question is how we can use the seed DB concept with the Parse local datastore. Because it is not possible to identify where Parse is storing the local datastore in iOS/Android. Also, we hope when the app installs for the first time from the store, Parse will create a new local datastore. So how shall we sync the huge contents initially to the Parse local datastore.
Can anyone give a suggestion for integrating seed DB with Parse local datastore.
Your best bet here is to seed your app with a Core Data database, then synchronize the Core Data to Parse incrementally. Essentially, you would start with a Core Data database on the initial load and slowly transition to using Parse directly, or alternatively, you could use the Core Data as your primary connection and have it sync with parse as needed, like so:
UI/Local Controller <==> Core Data <==> Parse.com
This is too big a question to give a full code example, but I can point you in the right direction with a solid framework build specifically to do this job:
https://github.com/8020world/FTASync
I wrote an application in android which will sync with SQL-server database that is sitting on my Local Server.
i used web service to connect my apllication to my database and it works perfect in local. Now i want to test it in real device "Samsung" but it gives nothing !
Any suggestion please. Thank you
When you say Local Server, do you mean the database is on your development machine and NOT the phone? You are not using SQLLite for storing data? Usual practice is to use SQLLite (or any other data storing techniques like SharedPreferences or Files) in android but all the data is stored Locally on the device. If you need server side storage, then you need to provide an interface (for e.g. web service) that the phone can talk.
I've created a pre-made database in SQLite for an Android app I'm developing. The app should interact and pull data from the database and display it on different 'Intents'. For now I just want to set up a local server on my Windows Computer for the database.
I was wondering what is the best way of doing so? I have little to no experience with setting up local servers or anything with regards to servers.
Thanks for any help!
There is no such thing as an SQLite "server". SQLite runs locally only through libraries. Also, Android database connections can not simply connect to anything on a server.
If you need a database on a server and an Android client to manipulate the data, you need to implement some kind of client-server architecture, for example using (RESTful) WEB services or any other client-server-communication.
I have been learning SQLite on Android and have done some tutorials on how to use it.
There is a question that I want to ask.
Is there a way to make my app connect to my MySQL database in a remote web server of mine so that it can read data and also write data to the database?
From what I've researched, SQLite cannot be used remotely and I would need some kind of Web service in between?
It's not easy to create a connection to MySQL from Android, if it's not impossible. With that, it's also not safe if for example someone decompiles your app they have access to your whole MySQL database if you don't limit it enough.
For those reasons, you can better use a (for example) PHP webservice to which the Android application sends all their requests. An example is available at http://www.helloandroid.com/tutorials/connecting-mysql-database.
I also suggest you use Android Asynchronous Http Client so you don't have to deal with connectivity issues and AsyncTasks yourself.
You can refer to this tutorial but you do need a web-server for it.
Request mechanism
Android App ----> webserver ------> database (mysql)
Respond mechanism
Android App <---- webserver <------ database (mysql)
Android App will use JSON or other to get the data and display it
You have to use Sqlite database and web Services both. First you have to save the data in local database i.e. SQLite database and then send this data to your server using web services and vice versa.
this link for web services
and this link for SQlite will help you understand.
Thanks.