Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to implement Client <-> Server <-> Database architecture in an Android application?

I am making an Android application. Since it is so simple, I first thought I could simply eliminate the need for Java application on the server which acts as a middleware. I tried directly connecting to the database using the JDBC driver for MySQL but my program is crashing so I'm not sure if Android "supports" the JDBC driver for MySQL.

So I am thinking of how to implement the application. Basically the application writes some data from a remote MySQL database and retrieves some data from a remote MySQL database.

Do I connect to a Java server program using sockets (or some other method of communication)? Or could I implement a direct connection to the MySQL database from the client application?

like image 482
user245120 Avatar asked Feb 13 '10 01:02

user245120


People also ask

How can we build client/server application in android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to res/layout/MainActivity.

What are the 4 different components of Android app architecture?

There are four components, each with a specific role: Room , ViewModel , LiveData , and Lifecycle . All of those parts have their own responsibilities, and they work together to create a solid architecture.

What is client and server in client-server architecture?

client-server architecture, architecture of a computer network in which many clients (remote processors) request and receive service from a centralized server (host computer). Client computers provide an interface to allow a computer user to request services of the server and to display the results the server returns.

What applications use client/server architecture?

Examples of computer applications that use the client–server model are ​Email​, network printing​, and the ​World Wide Web​. ○ Protocols: ​The special set of rules that end points in a telecommunication connection use when they communicate. ​ ​Examples: TCP/IP, HTTP, FTP and etc.


1 Answers

I tried directly connecting to the database using the JDBC driver for MySQL but my program is crashing so I'm not sure if Android "supports" the JDBC driver for MySQL.

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.

Do I connect to a Java server program using sockets (or some other method of communication)?

It doesn't have to be Java. It just has to be something designed for use over the Internet. As Mr. King's comment suggests, Web services have been used for this for much of the past decade. For Android, REST Web services are probably the easiest to consume, since there is no built-in support for SOAP or XML-RPC. But whether the Web service is implemented in Java, or PHP, or Perl, or SNOBOL, is up to you.

Well, OK, perhaps SNOBOL won't be a viable option. :-)

like image 180
CommonsWare Avatar answered Sep 24 '22 18:09

CommonsWare