Android apps connect with database server - android

I am trying to learn to implement android apps to get news, promotion message, and calendar from server. What is the best and easy way to communicate with database server? using JDBC or other methods?
Thanks

Using JDBC?:
In the words of Commonsware:
Never never never use a database driver across an Internet connection,
for any database, for any platform, for any client, anywhere. That
goes double for mobile. Database drivers are designed for LAN
operations and are not designed for flaky/intermittent connections or
high latency.
On the client side (Android app), you can use SQLite to store data locally. It might not be necessary at all actually. For instance, it can be used for offline features, search, etc. For client-side, read up on this simple post
On the server side (whatever server side technology you know or want to learn), you can use whatever language, whatever database on whatever server OS you want. This part is commonly called the back-end, which will store your data while your app communicate with it through HTTP.

You can use json to parse data between server and the android device. In the server you can use jdbc with json if you are using servlets in the server.

To communicate between a server and an android device you can use JASON. See following links for some help.
http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
https://www.learn2crack.com/2013/10/android-asynctask-json-parsing-example.html
https://www.learn2crack.com/2013/10/android-json-parsing-url-example.html
Also in the device to deal with data within the device you can use SQLite. And in the server you can use jdbc if you are using servelets.

To communicate with Database server You should use web service API such REST , soap

Related

android auto sync mysql to sqlite [duplicate]

I am developing an android application. I want to update the local SQLite database with MySQL database on server. I am not able to figure out that what is the most appropriate and standardized way to do so?
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 may want to take a look at fyrecloud.com/amsler This is source code for a demonstration Android application that implements MySQL replication between a MySQL server and the SQLite db on an Android device.
Amsler rests on two pillars:
It communicates with the MySQL server using the MySQL Client/Server protocol in order to connect to the server for authentication and for receiving replication events as they occur.
It uses the Antlr lex and parse software in order to lex and parse incoming replication events and then to translate the MySQL commands into equivalent SQLite commands.
This is great for one-way replication. You can simulate two-way replication by modifying the MySQL server indirectly via RESTful type methods and then watching while MySQL sends a new replication event back.
Accessing a server via REST is easy enough. However, modifying an existing MySQL installation in order to support serialization presents too many headaches to enumerate here. Amsler takes advantage of pre-existing replication services. REST also depends upon some polling strategy in order to keep the local device reasonably up-to-date. Again, many problems with this approach. Amsler maintains a TCP/IP connection to the server which enables server-push notification of updates.
The most difficult part of Amsler is in figuring out the lexing/parsing. The Syntax between MySQL, SQLite, and the various versions of the same have many subtle differences. So many differences that it's impractical to provide a shrink-wrap translator and instead you must resort to modifying the grammar yourself.
Nevertheless, good, bad, or ugly, here it is. Take a look and maybe the glove fits.
This is probably going to be helpful: sync databases Mysql SQLite
The real answer is that there is no standard or built in magic way to just copy a MySQL database that lives on a server somewhere to a device. You will have to implement either a webservice or somehow convert the MySQL db on the server to the android sqlite implementation and download that file into your app's data directory (not a route I'd recommend taking).
Late to the party, but http://www.symmetricds.org/ is a good solution.
Java, runs on Android too.
LGPL.
Can handle 10,000's of clients.
There is no standard way. Depending on your needs you can e.g. use webservices in REST or SOAP protocols or more binary data exchange.

How to connect android to python web services and MySQL database

I'm new to Android and to web services in general.
This is what i gotta do: My company has a back end website(for the client to monitor the sales) that's used to manage/monitor sales on some stores and it connects to a MySQL db to store data about sales and users(usernames and passwords).
What I want to do is to get data from that database and to add (sync operations) new rows, all of this from my android app.
I googled this many times and it came up with some similar projects but using another languages.
I would like to see some code samples if possible and some how-to theory, what theory should I follow when developing this, how and what ways of communicating between android and python web services and from the web services to the MySQL database.
Thank you in advance.
You will need a working API, that allows you to communicate to the web service from the android application. I would read into how to write an API and how to build a RESTful service using JSON as a way of communicating between server and android app. There are alternatives to JSON, but JSON is better suited for Android than perhaps AJAX and soap is being used less and less. (Can ajax call be done in Android? It can but has limitations)
(I could only post two full hyper links as i don't have enough reputation yet to do so, you may have to remove the spaces)
API:
http://sharismlab.com/blog/2012/07/21/how-to-write-an-api-for-your-web-app/
REST:
www .restapitutorial. com/lessons/whatisrest.html/
JSON:
htt p:// www.r evillweb.co m/article s/why-use-j son/
You may want to check out restjee. It allows you to define and implement RESTful data access APIs without having to write any server side code. Works with just about any database.

Android : what Strategics or steps to connect my android app to SQL server

Friends
Any one can tell me ,, what Strategics or steps to connect my android app to SQL server ??
i want to developer android app , this app connected to Sql server direct , and whats best choices to do that ???
thanks for help
You could use a webservice to provide service orientated architecture (SOA).
For example you may have a database with a PHP/Java/.Net application connected to it. When a mobile device makes a web request to this application, it returns data to the device.
The data returned could be in a choice of formats such as json or xml. Personally I prefer json if mobile devices are involved as the footprint from json is smaller than xml due to its characteristics. However that said, should you need meta data in the response then xml maybe more useful.
There are many tutorials on this and libraries to help deserialise responses (GSON from google is good when Json is involved), therefore I am not going to reinvent the wheel when others before me have explained this before and probably better.
Finally; the use of a webservice allows for multiple platforms to communicate with your database (and other services you offer) and allows for any 'heavylifting' to be done on a server rather than a mobile device.
From your comments to Graham Smith's answer, I understand you prefer to connect to SQL Server directly, without an explicit webservice or other communication layer in between.
You have to understand: android devices are usually mobile, so an indirect connection that doesn't require the android device to be in the same network as the SQL Server (including the security horrors that brings along in an enterprise environment) is usually preferred.
Back to the actual question: you can us JDBC to access SQL Server from Android. Either use Microsoft's own JDBC Driver for SQL Server, or use the Open Source jTDS . The latter seemingly solves some connection problems some peole seem to be having with the Microsoft driver.

multithreading in android

I have an app in android,a kind of client-server in which the client has stored some gps data in Sqlite database and once connected with server it delivers it that data which at its turn stores it in it's own database for future manipulation!
Now the problem is that I have to create a server that accepts multiple clients and I cannot find a decent example in this way.I'm not using no services in combination with it!
Both my client and server are on android!!!!
I have already did the connection between client and server,but only with one thread(I mean my server can accept only one client at this moment!)
Is this suitable?
How to implement simple threading with a fixed number of worker threads
Thank u in advance!
If server is Microsoft based, .net web service can be used that can be accessible from multiple Android clients and work with database.
Your server is not on the Android device I guess, so I don't think the question is android related.
Check out this example of multithreaded server in Java and this one as well.
To communicate with database, see the Java JDBC tutorial.
Those examples are in Java, because that's what I am used to, but any other language will fit as well.
A simple POST request from the client to the server should be good enough. Encode the data in a suitable format (JSON/XML) and send it as a POST HTTP request.
I don't understand why you want to write your own server. I would just use a PHP/Python script running with Apache to receive the POST request and store the data in a database (MySQL, PostGre).
On your Android device, you should put all your code in an AsyncTask. Android uses the standard Apache libraries to make the HTTP request.

Connecting Mysql with Android

I am new for Android Development. Now I want to connect Mysql with Android Application for uploading data to the server. Please send any sample code for connecting mysql with Android.
There is no MySQL connection library for Android that I'm aware of, unless you can get the MySQL java library operational under Android.
Either way, you don't want to do this - that would mean exposing your MySQL server to the world for TCP connections. There's no way to tell what IP your device will be appearing from. Each mobile carrier has their own internet gateway for devices, and it's invariably a NAT firewall to boot. This would be require you to leave MySQL wide open to TCP connections from all IPs, a major security hole.
Instead, you should build up a web service that acts as a middleman between your app and MySQL.
You can use MySql to connect to your android application through a servlet using Apache Tomcat. You will have to put your SQL syntax into the servlet you created and in your Java insert the URI path for the servlet.
i believe you need apache tomcat to run a servlet for your sql, do you have it?
The way it should work is , you use the sql-lite database to store the data that is generated in your application.Then, when you have a fixed set of data,convert into a protocol buffer, transmit the same via web-services,depacket it and store into a mysql database at the server.
If you need to manage data in a private database, use the android.database.sqlite classes.
Not sure if android supports mysql.
Go through the Notepad Tutorial for information on connecting to sqllite
http://developer.android.com/resources/tutorials/notepad/index.html
Other than sqlite we can't connect with any other database.
Using sqlite is also not a good practice, better use web service calls.
It is because, some viewers will be having less memory phones, has we are doing the application global, we should think of these things.
For small requirements you can use sqlite.

Categories

Resources