How to connect android to MySql database server? - android

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

Related

How to connect to a SQL Database on an Android Kotlin app

I am building an Android application with Kotlin. I am not very familiar with Databases and Backend in general, I have only used AWS DynamoDB and S3. I want to try something else and learn SQL. I want to connect my app to a Cloud SQL DB like MySQL or PostreSQL. I can't use SQLite because I want the app to be served remotely and be accessible by all the users. I don't need a server, instead I would like to use a server-less structure where I make queries to the DB on function calls from inside my App. How would I do that? I read online about services like planetscale and raiway.app but I can't find a way to connect to my tables there. Are they perhaps web-only?
If you have a remote back-end you can use retrofit https://square.github.io/retrofit/ otherwise you can use room library https://developer.android.com/training/data-storage/room.
I understand that you aren't going to use a Server but in the case where you have to make queries locally, i.e. you have your database on your PC, you must use retrofit and for doing this you must make a small API that will send you JSON and you can process your queries easily with that. If not, you can use room to connect to sqlite, a small database that is default on android phones.
Some Links :
https://square.github.io/retrofit/,
https://developer.android.com/training/data-storage/room.

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.

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

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.

Is MySQL a Network Database?

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.

Categories

Resources