Android using mssql server [duplicate] - android

I'm currently developing a Field-Service application that stores data in the local sqlite database on an android device. At some point, usually after completing the data collection rounds, the local sqlite db is to be synchronized to a remote sql server db on the server, also i need to update some local table from sql server db.
Any suggestions as to how this could be achieved or engineered as a solution? Or even better, are there alternatives to synchronizing data in such an application?

I think that the best is using a intermediary like web services or your own TCP based logic layer for your application which would connect to SQL server and execute requests of your applicatation. Don't try to connect to your SQL server directly from Android. You can write
some backend code on your server (or webservice) and then call those code methods from your android device using Http.
And also there are many themes in stackoverflow like your:
How to connect Android to a database server
Connecting android with MS SQL SERVER 2008
About how to write web services. It's a big question, and you must choose technology, there are very many libraries, frameworks and platforms that help you to simply write a web service. You must choose communicating protocol, it may be SOAP, WSDL or maybe remove calling procedure, it may be rest application. If you use java stack, there are some popular frameworks at the moment:
Apache CXF
Spring Web Services
Axis2
You can start from reading what a web service is:
http://en.wikipedia.org/wiki/Web_service
Also some links which provide example of accessing web services from android:
Step by step to access web service from android
Android and soap web services
Accessing restfull web service with android

Another and much easier approach is to use a Virtual JDBC Driver that relys on a secured three-tier architecture: your JDBC code is sent through HTTP to a remote Servlet that filters the JDBC code (configuration & security) before passing it to the MySql JDBC Driver. The result is sent you back through HTTP.
There are some free software that use this technique. Just Google "Android JDBC Driver over HTTP".

You would have to keep a middle tier online server.Which may communicate to and fro between your application and MSSQL db.May be servlet or a request handler which synchronises between the SQLite and SQL Server db.

Related

Android apps connect with database server

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

how to connect android and mysql server?

I want to get the details from online mysql databse in android.
I have wrote a php script to get the details form mysql database and convert the result as json string and extract the details in android using some sort of methods.
I am new to android development I think there should be some simple way to do this. if so please let me know.
You can use plain JDBC API with JDBC connector, only one I know is working is mysql-connector-java-3.0.17-ga-bin.jar. Bear in mind that exposing a database directly in the cloud is a serious security risk, as passwords and connection details travel without encryption. Best solution would be to implement a REST or SOAP web service with proper scheme.
Check this answer with an example of JDBC API connection
An other approach is to use a Virtual JDBC Driver that uses a three-tier architecture: your JDBC code is sent through HTTP to a remote Servlet that filters the JDBC code (configuration & security) before passing it to the MySql JDBC Driver. The result is sent you back through HTTP. There are some free software that use this technique. This is secure because the database is never exposed directly and you may use SSL. Just Google "Android JDBC Driver over HTTP".

how to connect android to online database?

MySQL
Server: db4free.net via TCP/IP
Server version: 5.5.12-log
Protocol version: 10
User: alan89#88.198.43.24
MySQL charset: UTF-8 Unicode (utf8)
Web server
Apache/2.2.14 (Ubuntu)
MySQL client version: 5.1.41
PHP extension: mysqli Documentation
This is my online database and the name is imammuda. In the database there is a table named "Testing".
Now, I have 2 applications which are admin and user. Admin needs to login into the database server then update data, while user just retrieves data or tables from the server.
I was stuck here at how to code the bridge between Android and server.
Well, if you need to communicate directly with the database you can use the MySQL JDBC drivers: there are many many many security problems with embedding direct database access into your app, but that WOULD work (longer dialog at Is it sensible to connect a desktop client directly to MySQL?). You would need to pass the username/password into the app and then you can just use regular JDBC code to talk to the database.
Alternatively you will want to implement some form of HTTP web service to mediate access, perform the necessary data verification and do access control. That is honestly a longer discussion than can be performed in a single answer. As a number of other potential answers describe you will need to look at using HTTP client. Also, you will need to implement a web service in a convenient language: you can see a detailed discussion about writing a database access web service at Writing data into a database using a fully REST web service.
EDIT: interesting option might be http://htsql.org/

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