internet database to android app - android

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.

Related

How to use online database (specially on byethost7.com) in android app for inserting information?

I am making an android project which inserts information into mysql database via php code. I am able to do so on my local server (using xampp). I have taken a free webhosting byethost7.com domain http://hpisys.byethost7.com for using my database and php file from that server. I am able to open php page on internet and insert the information into the online database server. But via android app I am not able to insert information using the same php code. Please help me out of this.
If you are also using this data in a web project I would set up a RESTful service and get the data that way. If not I would use something like Firebase instead, as it will be much easier to set up.
Either way you will need to research those yourself. You should be able to find a lot of tutorials.

querying online database of free server via android app

I am creating an app which queries an online database. I am using a mySql db hosted on a free web server. Can I create web services on free servers? Also can I query a database from my app directly without using web services?
as RED_ has stated, you need Http POST to query your database. For the answer for free web server is Yes you can.
You can create some PHP file to execute and query specific functions Such as select and display list on your android App.
As far as i know, You are NOT able to query database directly and you need gateway to do this. what i mean gateway is some files that bridging your app and the server's db. This gateway can send and receive JSON or XML objects then your android app can consume it.
Some good tutorial to begin with:
http://www.codeproject.com/Articles/267023/Send-and-receive-json-between-android-and-php
or call webservice in android
http://androidexample.com/WEBSERVICE/index.php?view=examplecloud&scat=26
if you need more detailed description, just create another question thread.
hope this helps.
From what I understand you need a .php file on the server that you will Http post to. That will talk to the MySQL database and return the information. This may not be 100% accurate but I tried it on a small local server and it worked. You cannot directly talk to a MYSQL database from my understanding.
What else have you tried so far?
No you cant query the database from android with out some webservice or some sort of application that will be in the middle between the android application and the database .
and you can create a web service in your free host
Hope that Helps

Android SQLite to My MySQL Web Server?

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.

Creating a web/server database to be used with android app

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.

If i have a DB on the server, what is the best approach to query for data from my android app?

Im new to android development. I realized if DB were to be on the phone updating it would be tedious. So though keeping DB on the server is better of but retrieving data from DB to App is what im having doubts with.
You cannot connect directly to the DB, you will need a web service to do so. Look at the http.client to help you get started on this.
SQLite would be the best choice depending on what you're creating your application for.
The approach you may need to choose will be, have a service hosted on your server (could be written in any programming language) which retrieves/posts data from database and sends data in either JSON/XML format ( I did JSon format) to app. In your app use HTTPClient to get/post data to service hosted on your server. Parse the data using Android in built JSon API.

Categories

Resources