How to access SQL database with Web App and Android App - java

What is the best way to have a SQL database that can both be accessed by an android device via java code and by a web app via php code?
In my mind I imagined a MySQL database somewhere on the cloud that is accessed in all the normal ways by the web app using mysqli_connect and then somehow the same database calls are made in Java inside the android app.
But after some research it appears this may not be the way to do it. What is the way to do this correctly?
EDIT: It was suggested my question was too broad. What I want then is a database of some basic financial information which is stored on the cloud which is then able to be accessed via a web app written in the LAMP stack and via an android app (with java code).
It is a really simple problem but I am not sure what the best practice for such a problem is in android (I come from a web dev background)

The standard way to access a database for mobile application is different than a normal web page/application.
Mobile devices should never run queries in the database; What you do is create a web service that does all the queries in the database and then sends back HTTP responses in xml, JSON format to the mobile device for consumption.
At the same time you can create a web client that interacts with the web service the same way your mobile app does. This way if you get erroneous data you can debug the web service without having to recompile the code in the mobile app.
Do a Google search for restful web service

Related

Read and display SQL table from network on Android application using SQLite [duplicate]

I am developing an application which is associated with a website. My application home screen contains login and register buttons. In user registration, all field values have to be stored in SQL Server.
Is it possible to connect to SQL Server from a mobile Android application? If so how?
On your website, I would create services that expose just the information you will need in your Android application. Never pass SQL strings. As Robin said, that's a major security issue. Then just consume these services in your app.
That sounds like a security disaster waiting to happen. How are you going to prevent people doing unauthorised transactions against the database?
I don't know a single company that intentionally exposes their SQL database directly to the world, i.e. without forcing everything to go through a web interface.

Connecting SpringMVC app to MBaaS for Android Application

I'm trying to create native Android app with MBaaS e.g. on parse.com where clients could enter some data. The thing is that I would also like to create some admin side web app (e.g. in Java SpringMVC) which could read that user related info from MBaaS service. Is it possible to connect SpringMVC app to MBaaS service? If not, what are my options?
Parse.com has REST API to access your data, so you can write separate web application with admin interface and fetch data from Parse.com via REST API.
But remember that Parse.com won't host your Java application. You'll need to host it on your own.

Connecting Java Desktop to Cloud Interface

I have a Java desktop application which stores data into a SQLite db every 10 mins which is stored locally in the user's system. I have a cloud interface to visualize this data which uses PHP and MySQL.
I need to fetch data from the local db of the users. I think I will have to write a RESTful web service in Java so that the database which is locally stored is not exposed and the data is obtained by the web service.
I am a bit confused with this. Am I going in the right direction here?
You're on the right track. Your desktop application can connect to the cloud server and upload its information. You'll need to create an http request in your desktop application.
I think you should maybe approach this the other way round, rather than the web service getting data from your local system, your local system should upload its data to your cloud interface, perhaps using a RESTful web service on the server rather than the client.
Hope that helps.

How Connect to Remote MySQL server through Android App via JDBC

I first successfully connected via JDBC to a remote MySQL server with a Java program. That I understand how to do. My goal is do the same thing with an Android application and display data from a remote MySQL server.
Question 1 Can someone explain the process outline to do this via Android ? (I am new to Android and am a little stronger with Java, could use a little guidance).
Question 2 I found this tutorial on javatutorialpoint.com titled: Android MySQL Client but it wants me to use the SOAP API. Not sure why, if someone could explain.
Not asking for it to be done for me. I just want someone to outline the main steps in order to make it happen. Just the process that needs to occur is all I am asking.
Question #1:
I stumbled upon this link some time ago:
http://docs.oracle.com/cd/E17076_02/html/installation/build_android_jdbc.html
(Disclaimer: I haven't read the whole tutorial myself)
It tells you what's needed for getting the MySQL connector to work with Android.
Basically, from what I know, the standard MySQL connector for Java, doesn't work out of the box for Android. You'll need to build it on your own.
After building the connector, you can include it in your Android project, precisely the same way as you do in a normal Java project.
Your Question #2:
SOAP is a mere layer of abstraction, for not working directly on the database. If you use a layer like SOAP, you can swiftly change your database layer without affecting much of the communication from-and-to the Android app.
You can use the same methods in Android you used in Java (Android is written in Java, after all, and you are able to use the majority of its libraries in android). However, be careful with doing so.
It would probably be better from a security standpoint to set up a web service to communicate with the database, rather than you allowing your android app to communicate directly with it, which would actually require you to embed your mysql username and password in the app code. A SOAP or RESTful web service could enable your server to communicate with the DB and then serve the data from it to your app.
It's done the same as in Java (Android apps are build in Java unless you're using the NDK).
You don't need SOAP if you only want to get data from a remote DB.
See this question.

Android Application communicating with GWT Application

I am developing a mobile application for Android. The application will act as a front-end for another GWT-application I have running on appspot.com. To communicate between the two, I need to send data from the client (Android Applcation) to the server (GWT-application), which must then be processed and data sent back to the client. What would be the best way to accomplish this? By "best" I mean simple enough for me to understand and implement, but also in line with good practice.
Any advice is greatly appreciated, as I am very new to GWT and can not find a lot of support on the internet.
Thanks!
I don't have much experience with Android application development but I guess with "sending data to the GWT application" you mean sending data to your App Engine backend/server.
In the end GWT is just compiled to plain Javascript and runs in the browser. So I don't see how you want to communicate with the GWT part of your app.
However you can send data from your Android app with the backend running on App Engine and eventually the data can be displayed in your GWT application accessed by any browser (mobile, desktop, etc).
For that I think you can either go one of two routes:
Create an HTTPRequest from your Android app to the backend using JSON or XML as a data protocol
Use RequestFactory (internally uses JSON) in your Android app (There is a special Requestfactory_client.jar package for that. See here for more details).

Categories