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...
Related
I have a script in java that works like a crawler and saves data in MySql DB. What i want to do is build a Mobile App(Andriod/ios) which will connect to mysql database retrieve results and just show it to the user.
What is the best approach to this ? I tried to use Flex UI with PHP as my server client but was hoping to know if there is a better solution ?
The fastest would be to make android fetch a page in XML, typically on the server and display its contents(If displaying contets is your desired result).
else
You need to implement a script on your server, your POST interacts with that script and inturn that script works with your database.
A typical scenario will be:
Java HTTP POST ~~~> PHP ~~~~> MySql.
PHP will as well help you encode the result in JSON and post it back to your client.
Try using jdbc or jtds library to connect android app with mysql
I used jdts library for connecting mssql db using android app.
http://jtds.sourceforge.net
For mysql jdbc might work
I want the users of my app to view an internet database, download some records of it into the database that is built in the app (not online db) and also to be able to upload some records to the online database.
I already have the database inside my app and my question is how can I make an online database that my android app could see, download from and upload to?
Android supports JDBC poorly - or let's be honest, not at all. Your best option is to create a Web server that wraps your database to a REST API. PHP is the most common language, while not the best, a lot of tutorials and snippets are available, so I would go with that. You'll have to wrap your database requests into HTTP requests and send it to the server.
For every query you'll plan on running, you'll have to create a PHP script that receives the HTTP parameters, builds the SQL query, and creates a structured XML or JSON response from the received data. This XML or JSON will than be sent to the Android client where you can parse it and obtain the data, do your syncing or such. I would suggest JSON, it's easier to read when debugging, consumes less bandwidth and has an easy to use parser in the Android API.
An easy lecture on PHP web service basics.
On using databases from PHP.
HTTP in Android.
JSON in Android.
Your online database should be on some server and you need to write a webservice to communicate your app to this online database(downloading and uploading purposes). your websrvice will also be hosted on some server. You then will be making webservice calls from your app to perform required modification to the online database.
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.
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
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/