Android-Ruby on Rails-MySQL [英] Android - Ruby on Rails - MySQL

查看:73
本文介绍了Android-Ruby on Rails-MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始开发一个Android应用程序,为此我们需要使用MySQL作为数据库,并使用Ruby on Rails来获取服务器端代码.我们还将在设备上使用SQLLite(将在需要时同步数据库).我在网上搜索,找不到任何可以作为基础的相关教程/示例.

I have started working on an Android app for which we need to use MySQL as database and Ruby on Rails for server side code. We will be using SQLLite too on device(will sync both DB as and when required). I searched the web and couldn't find any relevant tutorials/examples which can serve as a base to start with.

我已经看过MySQL和ROR教程,但对于将Android与ROR连接仍然感到困惑.

I have gone through MySQL and ROR tutorials but still has confusion on connecting Android with ROR.

有人可以分享一些相关的教程/代码片段,以解释技术的完整链接吗?我的意思是如何将数据从Android设备发送到MySQL,反之亦然.我从理论上了解这个概念,但不确定如何以及从哪里开始.

Can somebody share some relevant tutorials/code snippet which can explain the complete linkage of the technologies. I mean how to send data from Android device to MySQL and vice versa. I know the concept theoretically but not sure how and where to start with.

我很诚挚地问这样一个基本问题,或者我听起来模棱两可,但我是个初学者,需要完成此任务.谢谢您的期待.

My sincere apologies for asking such a basic question or if I sound ambiguous but I am a beginner and need to complete this task. Thanks in Anticipation..

推荐答案

此处简要概述了实现目标应该知道的内容.我将不做详细介绍,特别是因为我从未亲自使用RoR.请注意,其中某些部分可能与RoR并不完全相关,但其背后的一般思想仍然适用.我将留给您研究和弄清楚如何实现每个单独的组件.

Here is a brief overview of what you should know to accomplish your goal. I am not going to go that far into detail, especially since I have never personally used RoR. Note that some of these parts might not relate exactly to RoR, but the general idea behind it still applies. I will leave it up to you to research and figure out how to implement each individual component.

所有内容的一般流程如下:

Android应用程序< ==>网络< ==>网络服务< ==> MySQL

Android App <==> Network <==> Web Service <==> MySQL

请注意双箭头,因为数据将在两个方向上流动.

Note the double-edged arrows since data will be flowing in both directions.

Android App是客户端,Web ServiceMySQL数据库位于您的Web Server上.为了完整性起见,我仅包括网络"部分,但是一旦将数据发送到网络上,您就无需执行任何操作.

The Android App is the client, and the Web Service and MySQL database are located on your Web Server. I only included the Network part for completeness, but you shouldn't have to do anything once the data has been sent onto the network.

每个部分的简要概述:

Android应用:

Android应用程序是从Web服务器发送和检索数据的客户端.我假设在您的应用程序中,您将允许用户执行某些任务,这些任务本质上成为您要在某些时候发送到服务器的数据.

The Android App is the client that sends and retrieves data from the Web Server. I am assuming that in your app you are going to allow the user to do some tasks which in essence becomes the data that you want to send to the server at some point.

例如,用户应该能够输入他的名字和喜欢的动物.可以说,用户可以单击一个实际的提交"按钮.单击此提交"按钮后,它应该将数据包装为适当的格式,以便通过网络发送.最常见的两个是JSONXML.正确格式化数据后,您将需要使用某种类型的网络协议(例如HTTP)将数据发送到服务器.为了发送数据,您当然必须以URL作为目标.假设目标是www.example.com/webservice.php.此目标是位于Web服务器上的Web服务.

Take for example, the user should be able to enter his name and favorite animal. Lets say that there is an actual "Submit" button that the user may click. When this "Submit" button is clicked, it should wrap up the data into a proper format to be sent across the network. Two of the most common ones are JSON and XML. Once the data has been formatted properly, you will want to send the data to the server using some type of network protocol such as HTTP. In order to send the data, you of course must have some URL as the target. Lets say the target is www.example.com/webservice.php. This target is our Web Service located on the Web Server.

发送数据后,服务器将响应一些数据,此时您可以使用它进行任何操作.也许将其显示给用户,或者将其粘贴在SQLite数据库中,或者甚至都粘贴在这两个数据库中.

Once you send the data, the server will respond with some data at which point you can do whatever you want with it. Maybe display it to the user, or stick it in an SQLite database, or even both.

要记住的关键是没有魔法在发生.我刚刚描述的所有内容都将用Java代码实现,您将在某个时候在您的Android应用程序中编写该代码.

需要进一步研究并弄清楚如何用Java代码实现的关键思想:

  • JSON和XML
  • Java中的HTTP
  • REST和SOAP
  • 此处是一段精彩的视频,介绍了设置Android应用程序结构的可能方法
  • 请确保您正在其他线程上执行Android App中的所有网络操作.一种易于使用的方法是意图服务.
  • JSON and XML
  • HTTP in Java
  • REST and SOAP
  • Here is an excellent video on possible ways to set up the structure of your Android App.
  • Make sure that you are doing all network operations in your Android App on a different thread. An easy to use method is an Intent Service.

网络服务:

这通常是最令人困惑的部分. Web Service只是尝试访问Web Server的客户端的某些入口点.使用RoR时,我的解释可能会略有不同,但适用相同的想法.请注意,上面的目标URLwww.example.com/webservice.php. Web服务实际上是Web服务器上存在的PHP代码,称为webservice.php.在您的Android App中,当您使用HTTP将数据发送到目标URL时,Web服务代码将在服务器上执行(并且还可以访问您发送给它的数据).在Web服务代码中,基本上,您将提取数据(格式为JSON之类的数据),获取必要的部分,然后对其进行处理.在这种情况下,您很可能将查询数据库.在PHP中,很容易编写连接和查询也在服务器上运行的MySQL数据库的代码.当Web服务器检索数据库的响应时,您可以将其发送回Android App. 请记住,就像以前一样,这没有任何魔术.所有这些想法都是通过编写一些代码来实现的.

This is often the most confusing part. A Web Service is simply some entry point for clients attempting to access the Web Server. My explanation here might different slightly when using RoR, but the same idea applies. Notice above that the target URL was www.example.com/webservice.php. The web service is literally the PHP code that exists on the Web Server, called webservice.php. In your Android App, when you send data to the target URL using HTTP, the Web Service code will be executed on the server (and also have access to the data that you sent to it). Inside of your Web Service code, you will basically be extracting the data (which is in some format like JSON), grabbing the necessary parts, and then doing something with it. In this case you will most likely be querying the database. In PHP it is easy to write code that connects and queries a MySQL database that is also running on the server. When the response of the database is retrieved by the Web Server, you can send it back to the Android App. Just as before, remember, there is no magic going on. All of these ideas are implemented by writing some code.

主要研究思路:

  • Ruby on Rails Web服务
  • 如何使用Ruby on Rails访问MySQL数据库

MySQL数据库:

这是您将数据存储在Web服务器上的位置.我不会在这里进行深入探讨,因为这仅需要您大量阅读有关如何在Web服务器上设置MySQL数据库的内容.学习如何创建适当的查询(如SELECTINSERT等)也很重要.

This is where you will store the data on the Web Server. I am not going to go that in depth here because this is just going to require you doing a lot of reading up on how to set up a MySQL database on a web server. It is also important that you learn how to create the appropriate queries such as SELECT, INSERT and so forth.

主要研究思路:

如何在Web服务器上设置MySQL数据库

How to setup a MySQL database on a web server

如果您需要任何澄清,请告诉我!

这篇关于Android-Ruby on Rails-MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆