如何从安卓手机与服务器的数据库进行通信?[英] How to communicate with server's database from android phone?

本文是小编为大家收集整理的关于如何从安卓手机与服务器的数据库进行通信?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我目前正在制作一个应用程序,它将与将在服务器上托管的简单数据库进行通信.该数据库将只有三列,一个_id,标题和URL链接.我已经使用手机的本地数据库成功地完成了此操作,但我想要它,以便其他任何手机也可以访问相同的数据库.我将在计算机上更新服务器的数据库(添加新行),以便手机应反映这些更改.

我相信我也将在服务器上使用SQLITE来创建数据库.基本上,我希望所有更改都可以在服务器端进行处理,而不是像我使用本地数据库那样从手机上进行操作.手机应该能够访问数据并相应地使用数据.谁能向我解释一下这样做的方法?

预先感谢您!

推荐答案

您需要通过Web界面公开数据库.一个好方法是使用 Restful Web Service .您可以将每一行表示为对象,并使用HTTP获取请求来检索它,HTTP帖子更新它以及HTTP PUT或HTTP帖子来插入新条目.当然,您需要使用Web技术和某种应用程序服务器.

本文地址:https://www.itbaoku.cn/post/102745.html

问题描述

I'm currently making an app where it would communicate with a simple database that will be hosted on a server. The database will only have three columns, a _id, title, and url link. I've successfully done this using the phone's local database using SQLiteDatabase but I want it so that any other phone can also access the same database. I will be updating the server's database (adding new rows) on the computer so the phones should reflect these changes.

I believe I will be using sqlite on the server too to create the database. Basically I want all changes to be handle on the server side instead of doing it from the phone like how I am with the local database. The phone should be able to access the data and use it accordingly. Can anyone explain me a way to do this?

Thank you in advance!

推荐答案

You will need to expose the database through a Web interface. A good way will be to use a RESTful web service. You could represent each row as an object and use an HTTP GET request to retrieve it, an HTTP POST to update it and an HTTP PUT or HTTP POST to insert new entries. Of course you need to use a web technology and an application server of some kind.