简体   繁体   English

互联网数据库到Android应用

[英]internet database to android app

I want the users of my app to view an internet database, download some records of it into the database that is built in the app (not online db) and also to be able to upload some records to the online database. 我希望我的应用程序的用户可以查看互联网数据库,将其一些记录下载到应用程序内置的数据库中(而不是在线数据库),还希望能够将一些记录上传到在线数据库中。 I already have the database inside my app and my question is how can I make an online database that my android app could see, download from and upload to? 我的应用程序中已经有数据库,我的问题是如何创建一个在线数据库,供我的android应用程序查看,下载和上传到?

Android supports JDBC poorly - or let's be honest, not at all. Android对JDBC的支持很差-或说实话,一点也不。 Your best option is to create a Web server that wraps your database to a REST API. 最好的选择是创建一个将数据库包装到REST API的Web服务器。 PHP is the most common language, while not the best, a lot of tutorials and snippets are available, so I would go with that. PHP是最通用的语言,虽然不是最好的语言,但是有许多教程和摘要可供选择,因此我会同意。 You'll have to wrap your database requests into HTTP requests and send it to the server. 您必须将数据库请求包装为HTTP请求,然后将其发送到服务器。

For every query you'll plan on running, you'll have to create a PHP script that receives the HTTP parameters, builds the SQL query, and creates a structured XML or JSON response from the received data. 对于要计划运行的每个查询,都必须创建一个PHP脚本来接收HTTP参数,构建SQL查询,并根据接收到的数据创建结构化的XML或JSON响应。 This XML or JSON will than be sent to the Android client where you can parse it and obtain the data, do your syncing or such. 然后,此XML或JSON将被发送到Android客户端,您可以在其中解析它并获取数据,进行同步等。 I would suggest JSON, it's easier to read when debugging, consumes less bandwidth and has an easy to use parser in the Android API. 我建议使用JSON,它在调试时更易于阅读,占用的带宽更少,并且在Android API中具有易于使用的解析器。

An easy lecture on PHP web service basics. 关于PHP Web服务基础知识的简单讲座。

On using databases from PHP. 从PHP使用数据库。

HTTP in Android. Android中的HTTP。

JSON in Android. Android中的JSON。

Your online database should be on some server and you need to write a webservice to communicate your app to this online database(downloading and uploading purposes). 您的在线数据库应该在某个服务器上,并且您需要编写一个Web服务以将您的应用程序与此在线数据库进行通信(下载和上传目的)。 your websrvice will also be hosted on some server. 您的Web服务也将托管在某些服务器上。 You then will be making webservice calls from your app to perform required modification to the online database. 然后,您将通过应用程序进行网络服务调用,以对在线数据库进行必要的修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM