为什么“直接数据库连接"的范例如此?不受Android平台欢迎? [英] Why is the paradigm of "direct database connection" not welcomed by the Android platform?

查看:99
本文介绍了为什么“直接数据库连接"的范例如此?不受Android平台欢迎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我说直接数据库连接"时,我的意思是在活动的上下文中使用类似JDBC的驱动程序来调用和运行远程数据库查询,就像使用SQLite数据库存储本地参数一样.

When I say "direct database connection", I meant to use a JDBC-alike driver to call and run a remote database query within the context of an activity, just like using an SQLite database to store the local parameters.

直到我意识到,我几乎无法在Internet上找到有关这种数据库连接方式的任何教程或文档,尽管大多数(如果不是全部)Android设备都无法连接到不稳定的Wi-Fi/3G网络,数据库应该这样做.

Until I realized that I could barely find any tutorials or documents on the Internet regarding this way of database connection, I thought, regardless of the unstable Wi-Fi/3G network bore by most if not all Android devices, to connect to a database should be done like so.

即使在Android SDK中,本质上也仅支持本地数据库访问(也称为android.database.sqlite).它在 java.sql API的说明中进行了说明, 您必须提供自己的JDBC驱动程序,才能使用此API.

Even in Android SDK, only local database access (a.k.a android.database.sqlite) is supported intrinsically. And it's stated in the description of java.sql API that you must provide your own JDBC driver in order to use this API.

然后我开始意识到,直接连接数据库的意图是否在Android领域中居于首位.

Then I started to realize if my intention of directly connecting a database is incorrectly in the first place in the realm of Android.

我已经阅读了许多书籍,Wiki和论坛,其中包括Stack Overflow上提供的众多答案.在我看来,很多人都专注于完成工作,而讨论通常始于如何为我的Android设备设计RESTful Web服务?".但是,我需要透彻的理解!而且,我还需要来自原始Android开发人员的权威引用.

I have read many books, wikis, and forums, including numerous answers provided on Stack Overflow. It appears to me that many people are concentrating on getting something done, and discussions used to start with "How can I design a RESTful web service for my Android device?". However, I need a thorough understanding! And I also need authoritative citations from the original Android developers.

推荐答案

一些原因(但并非几乎所有原因):

A few reasons (but not nearly all reasons):

  1. 不存在:Android上没有(受支持的)JDBC驱动程序.

  1. Not existing: there are no (supported) JDBC drivers on Android.

身份验证:您希望对公共网络上的用户进行身份验证:

Authentication: you want users on a public network to be authenticated:

A.与服务器对话时,每个用户都必须具有自己的凭据(以某种形式).在您的应用程序中添加一个用户名/密码很麻烦.

A. Each user must have their own credentials (in some form) when talking to your servers. Having one username/pass baked into your app is asking for trouble.

B.您不希望数据库提供身份验证.为此,您需要一个单独的身份验证层.

B. You don't want your database to provide authentication. For this you need a separate authentication layer.

标准协议:如果要确保您的应用在所有网络上运行(特别是在锁定的公司网络上),则需要使用HTTP/HTTPS.这是(几乎)在所有地方都有效的唯一协议.

Standard protocol: if you want to make sure your app runs on all networks (especially on locked-down corporate networks) you need to use HTTP/HTTPS. It's the only protocol that works (almost) everywhere.

业务逻辑分离:如果您支持不同的设备平台(Android,iPhone等),那么将所有业务逻辑都存储在服务器上是明智的.您应该在服务器上执行此操作,而不是调用JDBC,然后在设备上执行业务逻辑.这样一来,您将符合 DRY (不要重复自己)的做法, '将更易于进行单元测试.

Business-logic separation: If you support different device platforms (Android, iPhone, etc..) then it's wise to have all business logic on the server. Instead of calling JDBC and then performing business logic on device, you should do this on the server. That way you will conform to DRY (don't repeat yourself), and also it'll be easier to unit test.

这篇关于为什么“直接数据库连接"的范例如此?不受Android平台欢迎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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