如何从 MySql 服务器到 Android 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2898823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get from a MySql server to an Android app?
提问by Fabian
I have a MySql database with some sports results in it. I want to write an Android application to display these data on mobile phones.
我有一个 MySql 数据库,里面有一些运动成绩。我想编写一个Android应用程序来在手机上显示这些数据。
I′ve searched on the internet for this issue, and I think it is not possible to have a direct connection between the MySql database and the Android application. (Is this right?)
我在网上搜索过这个问题,我认为MySql数据库和Android应用程序之间无法直接连接。(这是正确的吗?)
So my question is the following: How can I have access in the android application to the MySql database in order to display some of the data?
所以我的问题如下:如何在 android 应用程序中访问 MySql 数据库以显示一些数据?
采纳答案by James Black
You may want to look at C2DM (http://code.google.com/android/c2dm/).
您可能想查看 C2DM ( http://code.google.com/android/c2dm/)。
A common way is to write a REST web service and have Android call that and get the data from the server.
一种常见的方法是编写一个 REST Web 服务并让 Android 调用它并从服务器获取数据。
If you want to push it, if the data is small enough, you could use SMS and just send the data as a text message to the device.
如果你想推送它,如果数据足够小,你可以使用 SMS 并将数据作为文本消息发送到设备。
You don't want to open access to your database so by using the web service you can better protect your database.
您不想打开对数据库的访问,因此通过使用 Web 服务,您可以更好地保护您的数据库。
回答by prolink007
Try this method out. I will be using this method for the current project i am working on.
试试这个方法。我将在我正在处理的当前项目中使用这种方法。
You basically create a php script on a server and use http posts to send the data to the script, read the tutorial linked below for better explanation.
您基本上在服务器上创建一个 php 脚本并使用 http 帖子将数据发送到脚本,阅读下面链接的教程以获得更好的解释。
回答by Exile
There are many approaches to this, but I would use an SOA.
对此有很多方法,但我会使用 SOA。
Your mobile application will need to follow a typical service-oriented architecture (SOA) and will need three distinct elements: an external database; a web-service; and a mobile web-service client.
您的移动应用程序需要遵循典型的面向服务架构 (SOA),并且需要三个不同的元素:外部数据库;网络服务;和移动网络服务客户端。
You will need to create a web-service using something like Java EE that receives a request from the locally installed android application, and responds with the required data from the external MySql database.
您将需要使用 Java EE 之类的东西创建一个 Web 服务,它接收来自本地安装的 android 应用程序的请求,并使用来自外部 MySql 数据库的所需数据进行响应。
I am using the KSOAP for android libraries to do this, but should ideally be using REST.
我正在使用 KSOAP for android 库来执行此操作,但理想情况下应该使用 REST。
回答by Devrath
Step by step procedure for using Mysql to store data in local machine using android to enter data
使用Mysql将数据存储在本地机器中使用android输入数据的分步过程
Android Connecting to MySQL, PHP
Android Connecting to MySQL, PHP
This is one of the simplest tutorials on the net regarding data flow from your Android app to PHP script then finally is stored in your MySQL database.
这是网络上最简单的教程之一,内容涉及从 Android 应用程序到 PHP 脚本的数据流,然后最终存储在您的 MySQL 数据库中。
Hope it helps
希望能帮助到你