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/
Related
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.
I have experience building android applications but now I would like to start building applications that interact with some sort of web database to push and pull data.
What type of database should i set up on a remote server for my application to interact with? From what i understand I need a database on the remote server and some service that my android app can communicate with?
What can i read that will clear up how this works and how i can get started?
The easiest (and often most flexible) combination in my opinion is PHP and MySQL. PHP as the scripting language which is called (via http) from the app, and handles all the database access. MySQL as the database. PostgreSQL is also an option for the database, of course. And if you have access to .NET, JSP or something like that, that's also an option. But a web server with Apache, PHP and MySQL is free, powerful and easy to maintain, and most/many web hosts have them.
The way it works (which is the same no matter what kind of webbased services/servers you chose), is this:
- The database is installed on the server
- You have a web area (on the web server) which has access to the database (this is how it will be with a typical web hotel solution)
- You place your scripts (f.ex. PHP) in the web area
- The web scripts access the databse, with functions for fetching and/or storing information
- Your app uses httpclient or something similar to send http GET or POST requests to the PHP scripts, either sending information or asking for information, or both
It's also quite possible to write database access code directly in your app (this is very easy in Java and C#, compared to languages like C og C++). However, most hosts don't allow remote access to their database servers, so you'd most likely have to set up a database server yourself. Also, accessing the database server directly is a security risk, and I wouldn't recommend it.
As to what you can read, there's lots and lots of tutorials, howtos and concrete examples on the net. Search for "php access mysql databse", f.ex., for ideas on how to write php scripts that handles the database transaction(s). If you have a more detailed decription, I might be able to point you to something more specific.
I strongly suggest adding web service layer between your application and database, using i.e. JSON or XML. Exposing DB directly ma be security risk and is rarely the way to go.
I want to insert, update, show records from an android app to a database (online) which will be installed on an android mobile.
So,my question is; which database is perfect?
MySQL
SQLite3
Any other
It's impossible to use MySQL in Android. Other SQL types neither. The best way is to use a MySQL database and get the information via PHP. Encode it to JSON in PHP. You can get the Web page in Android and decode it in Android.
Is mysql db is network database
MySQL (like many other database servers including Postgres and Oracle) can be accessed either through a local socket or via TCP/IP. (You also mentioned SQLite, this is a file based database and does not have a network server AFAIK).
There may be libraries for Android that implement a MySQL client, but a few minutes with Google didn't turn any up for me.
Generally speaking, network access to MySQL should be limited to private networks and not end clients anyway.
If you want to access a database from a client application over a network, you are usually better off by building an HTTP based API (preferably one that is RESTful) and letting the client software connect to that. This gives you more control over what clients are allowed to do with the database.
You can build such an API in just about any language you like. If you are working with Android, you might prefer Java. My preference would be Perl. Python is a good option, etc, etc.
which database is perfect?
Nothing is perfect. Giving a recommendation for a specific database would be drifting into "Not Constructive" territory, even if you were more specific about your requirements.
In my project, I have to connect an Android mobile phone to a remote MySQL database server, to insert data to the database and get the data back later.
However, it seems that Android OS only supports the SQLLite database that works LOCALLY inside the phone.
Does anyone know how to connect an Android phone to a remote MySQL (or MSSQL, or Oracle) database server ?
Thank you!
You will have to access the database using some sort of Remote Method Invocation (RMI).
My personal recommendation is to create a RESTful HTTP interface to your MySQL database on the server. This may be a bit more work, but is preferred for its ease of use and compatibility with any system (that can make an HTTP request that is).
Essentially, you should create HTTP endpoints to Create, Read, Update, Delete (CRUD) data from your MySQL database on your server. Your Android client would then make calls to these HTTP endpoints to perform the corresponding CRUD operations. Of course you do not need to do the typical CRUD operations, you can make your endpoints interact with the database however you wish.
Like I said, a big advantage to this is how extensible it is. You can create another client, on another system, in another language, and all you need to do is make the proper HTTP call.
try using Jdbc... for more read this http://developer.android.com/reference/java/sql/package-summary.html
I've been looking for a week now... I need some help connecting to a remote database... I want my app to get data out of the database and update the database...
I've tried this but i don't understand it.
Easiest way to connect a Mobile (ANDROID, iPhone, Symbian, WP7, you name it) device to a Data Base is to write a HTTP based proxy for your database.
This is:
ANDROID -> HTTP -> APPLICATION SERVER -> DATABASE
And then the other way around to get results:
DATABASE -> APPLICATION SERVER -> HTTP -> ANDROID
In this scenario, you will write a HTTP based application in your favorite language (PHP, Python, Perl, Java, .NET) and deploy it in your favorite Application Server (Apache, Tomcat, IIS) and, in that application you will publish URLs your Android app will access to send/retrieve data to your database.
I think rather than connect to a database remotely, you want to use REST services to get and post data to your remote database.
You can create a REST service to wrap your remote database query and return via http, JSON (which I prefer) or XML.
In your android app you can do an http get or post to consume the aforementioned service
Create the database in the server
Write server side program to store and retrieve data
write the android program to access the data using HttpPost class
All the best...