简体   繁体   English

Android从数据库中获取数据

[英]Android fetch data from database

I've decided to try out some DB connections for my android applikation. 我已经决定为我的Android应用尝试一些数据库连接。 However I need some advice regarding structure. 但是我需要一些关于结构的建议。

I came to know that in order to fetch data from DB with Android I need to use php scripts. 我开始知道,为了从Android获取数据,我需要使用PHP脚本。 I'm a total novice in this area and for me it sounds a bit akward. 我是这个领域的新手,对我来说这听起来有点尴尬。 Therefore I figured I could create a Java server which the application connects to, and among other things this server also fetches data from the DB and returns. 因此我想我可以创建一个应用程序连接的Java服务器,除此之外,该服务器还从数据库中获取数据并返回。

In a performance perspective, what's best? 从绩效的角度来看,什么是最好的? Let the application itself fetch data from the DB, or connect to the server which fetches it for you? 让应用程序本身从数据库中获取数据,还是连接到为您提取数据的服务器? How about security? 安全性怎么样? For clearance, I will have a Java server anyhow to take care of other things. 为了清除,无论如何我将有一个Java服务器来处理其他事情。

在此输入图像描述

Sorry about the Vista paint skills. 对于Vista绘画技巧感到抱歉。 Thanks for any input! 感谢您的任何意见!

Like others have said it doesn't matter which you use PHP vs Java. 像其他人一样,使用PHP与Java相关并不重要。 But you're on the right track. 但是你走在正确的轨道上。 Most developers create a web service on their HTTP Server and the app talks to that. 大多数开发人员在他们的HTTP服务器上创建一个Web服务,应用程序与之对话。 That's usually in the form of JSON or XML strings over HTTP. 这通常是通过HTTP的JSON或XML字符串形式。 Popular choice is using the REST architecture which essentially tells you that stuff you access on the service are resources and you structure your service based on that. 流行的选择是使用REST架构,它实质上告诉您,您在服务上访问的内容是资源,您可以基于此构建服务。

For the PHP vs Java question it's really up to you so do which ever you can setup faster and are more familiar with. 对于PHP与Java问题,它真的取决于你这样做,你可以更快地设置并且更熟悉。 I will also say Java has productivity advantages in Android's case because you can create plain old java objects as your models for results and share that code between the server and your Android client. 我还要说Java在Android的情况下具有生产力优势,因为您可以创建普通的旧Java对象作为结果模型,并在服务器和Android客户端之间共享该代码。 You get this because you can use something like Gson library which serializes and deserializes objects into JSON format. 你得到这个是因为你可以使用类似Gson库的东西,它将对象序列化和反序列化为JSON格式。 You can also use Google AppEngine for hosting your Java code too. 您也可以使用Google AppEngine托管您的Java代码。

Well this problem is irrelevant in context to android programming i would say. 那么这个问题与我想说的android编程的上下文无关。

Assuming that You are returning the extracted data to your device in json format, the entire performance issue is sort of restricted to the performance of java or php in retrieving data from database and converting it to json and sending to the client. 假设您以json格式将提取的数据返回到设备,整个性能问题仅限于java或php在从数据库检索数据并将其转换为json并发送到客户端时的性能。

And as far as simple operations are considered the efficiency wont matter much in both cases, it is just a matter of preference on the developers part. 并且就简单的操作而言,效率在两种情况下都不会很重要,这只是开发人员部分的优先选择问题。

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

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