18

我正在为我的第三年项目写一份申请。该应用程序将需要与外部 mySQL 数据库交互。应用程序将从数据库中检索数据并在 ListView 中将其显示给用户。

我很清楚应用程序将具有什么样的功能。我也花了很多时间使用 ListViews 和本地 SQLite 数据库。我还对 HttpUrlConnection 类做了一些研究。

我只是想知道是否有人能够就如何访问这个外部数据库向我提供更多指导?

是否需要我编写一个 Web 服务来处理交易?如果是这样,那会涉及什么,因为我还没有在我的课程中遇到过 Web 服务。

任何建议将不胜感激。此外,我的应用程序旨在用于 ICS v4.0.4。

感谢大家!

4

5 回答 5

12

是的,您必须创建 Web 服务才能与外部数据库(在您的情况下为 MySql)进行交互。在 PHP 中创建 Web 服务非常容易,因为它具有一个将您的数据库数据转换为 JSON 的功能,您可以轻松地解析 JSON 数据并将其显示在 Listview 中或相应地显示您的要求。

以下是一些有用的链接,可帮助您获取更多详细信息:-

http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/ - 最好的

http://www.coderzheaven.com/2011/04/08/android-phpmysql-connection/

http://blog.sptechnolab.com/2011/02/10/android/android-connecting-to-mysql-using-php/

希望能帮助到你。

于 2012-10-09T17:40:41.197 回答
2

I would recommend that your android application talks to a restful service (intermediary service that is talking to your database) that will return the database objects you require. so its not a direct connection to a database but its a good example on this type of connectivity.

于 2012-10-09T17:35:23.363 回答
1

Will it involve me having to write a web service to handle the transactions?

Yes, if the database is not on the device, you will have to access it with network requests, which will have to handled by something.

what would that involve?

That depends on a lot of things. You can write a web service in pretty much any language you want as long as the server hosting it supports it. You could you Python, Ruby, PHP, Perl, Java, or .NET (if you have the framework) to name a few. Handling the actual database requests would have to be done on the server, which would return data back to your app - probably as JSON.

于 2012-10-09T17:34:56.263 回答
1

这个链接肯定很有帮助。完全按照此链接进行操作,但请确保按照此链接的说明WAMP服务器的httpd.config文件进行以下更改

于 2015-06-17T21:57:25.050 回答
0

您需要有一个虚拟主机来在线存储脚本。您可以在例如 php 中编写此脚本以在数据库中插入用户数据。在您的应用程序中使用 Volley 来处理脚本。获取用户数据后,调用脚本并收听结果:

  • 这是用户第一次登录
  • 用户已经注册
  • 发生了错误

例子

于 2015-10-31T21:40:32.197 回答