简体   繁体   中英

Developing Android App with Amazon EC2 Database

I've looked around trying to find an answer to this question, but have so far been unsuccessful. I have a current version of an Android mobile application that stores items in the local database, and I'm trying to hook it up to a 'cloud' database (not sure if this is the right term) so that other people that download the app will be able to view and post things to the database.

I have an ec2 service set up, with my LAMP stack installed. I have the database set up on this server ready to go. How do I go about hooking up the Android application so that it can communicate (insert/view/delete items) with the database? I am a new developer so any help/insight/guidance you have is much appreciated!

You haven't mentioned the type of database you have setup on cloud. I am assuming it to be some kind of relational database (eg MySQL). You can use standard JDBC connection from a regular java code but it is not yet possible (supported) to do it directly from Android code.

I faced a similar issue, what I did was this:

  1. Create a Servlet and deployed it on GAE (Google App Engine).
  2. Make an HTTP request from your android application code to this Servlet (SELECT/UPDATE/DELETE).
  3. Initiate a JDBC connection to your database (on EC2) from that Servlet.
  4. Shoot the SQL statement to the database.
  5. Get the result and send the response back from servlet to your android code.

There may be other better solutions but I could not find any and tried this on my own, it worked like a charm, multiple times.

After writing the previous answer, I kept on thinking of alternate solution.

FYI: This may or may NOT work !

  • Instead of hosting your servlet on GAE, you can host it on the same EC2 instance as your database, using tomcat or any other package.
  • This way your android code would communicate directly with the instance that has servlet and database deployed together.
  • In the servlet, you can shoot SQL queries internally and send the results back to android code.

How to host a servlet in Tomcat 7

添加新的安全组并将其与我的实例链接..为我工作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM