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

查看:112
本文介绍了如何从Android手机与服务器的数据库通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我相信我将在服务器上使用sqlite创建数据库。基本上我想要所有的变化在服务器端处理,而不是从手机,如我对本地数据库。手机应该能够访问数据并相应地使用它。

解决方案



您将需要通过Web界面公开数据库。一种好的方法是使用 RESTful网络服务。您可以将每一行表示为一个对象,并使用HTTP GET请求来检索它,一个HTTP POST来更新它​​,一个HTTP PUT或HTTP POST来插入新的条目。当然,您需要使用Web技术和某种应用程序服务器。


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.

这篇关于如何从Android手机与服务器的数据库通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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