Android database connection on a closed network - android

First time working with android. I'm look for a way that an android app can connect to a remote database. However, this is on a closed network with no internet connection. Just the phone and the server.
I wanted to know the best way to connect, if its through JDBC or if its possible through android's SQLite class, or something else?
The phone is running android 2.1 and the database is a MySQL database.
Any guidance is much appreciated.
Thanks,

As long as the device is connected to the network, which would have to be via wifi, you can access a MySQL database hosted somewhere on the network just like you normally would.
My advice would be to set up a RESTful web service on the server which hosts the database. Your Android client application can communicate with this web service using HTTP requests and the web service can talk directly to the database. I'd say this is the most common approach for working with remote databases when it comes to Android.
Android Client <==> RESTful Web Service <==> MySQL Database
Android has a couple different ways to communicate with a web service: HttpClient and HttpUrlConnection. I think the latter is generally the most preferred way nowadays.
As far as I know, JDBC is unsupported for Android, and the Android SQLite API is strictly for using an embedded SQLite database.

Related

Android application connecting to a public server database

I'm creating an application in Android, and I also have a virtual server in Amazon Web Services, because I'm trying to connect to a database hosted in there from my Android application; I'd like to know how could I connect to the AWS database (Microsoft SQL Server), I understand that the servers in AWS are visible publicly, but I'm lost here, Could you provide me some guidance on this? thanks!
Your best bet is to create a web service layer between your Android app and your back-end database. That way, your Android app talks to the web service via the HTTP protocol, and the web service (running on a web server with access to your SQL Server) talks to the database. This is the most common method for achieving the database connectivity you need.
You create your web services using whichever web technology you are most comfortable with; .NET, PHP, ColdFusion, or whatever. So-called RESTful web services are a nice way to do this. You can read about building RESTful web services with .NET here. Hope it helps. Good luck with your app.

Using Tomcat server to host android and web application opens too many connections

I have an Web application running on my Tomcat server v7.0. Now I'm creating an android app and it will connect to MySQL database. For this, I'm going to send requests to this server, and this server will get data from database to Android app.
Now, I'd like you to think on the situation: if I have 1000 users connected to my webPage and more 1000 users getting data from MySQL database (as I said, the server will be in the middle of the communication between MySQL and Android), will my Tomcat server open 2000 connections?
I'm know it's difficult to the server receives such number of connections at the same time, but what I'm wondering is: will Tomcat server closes connections once the request is done?
I don't know if it is useful to answer this question, but I'm using spring MVC framework in the web application and Android spring in the Android application.
That is what JDBC connection pools are for. Take a look at the documentation on how to configure them

Best way to get data from server using Android Emulator

Am developing Android program. Now I need to access MSSQL2008R2 remotely from one computer(client) to another computer(server).
Which is the best way to connect?
Such as, JDBC Driver, Web Service
If you developing the the mobile application for any OS like Android, iPhone, Blackberry etc. then you should use web service to get data from server.
Reason to use Web service.
If you use web services method to get the data from database server remain same and need to write once in webservice but in case of JDBC its only for java, In other cases you need to search other ways to connect to database server.

Server requirement

We are interested in purchasing a server for storing a MySQL database that is used by an Android application. Just to understand, does the server only need to support MySQL, or are other requirements for a server for mobile use?
Your Android application would probably not work directly with a remote MySQL database.
In general, you would use write a web service API to act as middleware, communicating with your Android application and the database. Your Android application would make HTTP requests to the web service, which would in turn perform CRUD on your database. In this case, your server would need both a web server (with support for Java or PHP or whatever language you choose to use for the web service) and a database server. See How to have Android app work with MySQL online database?
To access the database "directly" (like it was local), this could help: MySql remote database manipulation in Android
But you might need some additional server functionality, at least in the future. Then you could use a server which also offers PHP. PHP + MySQL are usually offered together, it's very common/popular and it's cheap. Since you don't seem to have any special requirements for the server functionality, PHP is probably suitable.

How to connect to a MySQL Database from an Android App?

I would like to connect to a MySQL Database hosted on the same server with a Tomcat Server from my Android App without using PHP. Is there any way to do this? I found some solutions but all use PHP.
Can I connect directly or do I have to do it through a Web server?
Because you're running on Tomcat I imagine the best way to access the database would be to write a webservice that handles the communication between the app and the server.
The webservice will be written in Java to run on TomCat using JSP.
I'm guessing you're trying to communicate directly with the MySQL database (i.e. run SQL commands on the database directly) but I don't think you can do this (although never tried or looked into it), I have always been under the impression that you need some code on the server to sit inbetween.
It should be common sense, that directly communicating with databases over the web is a "no go" security wise and with mobile devices a pain regarding the connectivity.
Setup a webservice with JSP or Grails (which I find comes with less workload) and deploy it to your tomcat server.
Hence the thought, you already have a Tomcat running, one assumes you have a java web app running. Try adding a webservice to that app or look in the documentation, if there already is one.
You actually cannot do this with Android the main reason is performance it is really expensive to keep a remote connection alive than rather just call Web Services on demand, and it is more portable.
So i recommend you to play around with your favorite language creating services that access to your database and digest the output (XML or JSON) with android.
BTW i also think this have been asked Android MySQL Connectoin and here is a nice tuto about it (but with PHP) it should be fairly easy to do it in Java.

Categories

Resources