JDBC VS Web服务为Android [英] JDBC vs Web Service for Android

查看:137
本文介绍了JDBC VS Web服务为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在我的困境有人回答用于连接哪种方法机器人设备MySQL或PostgreSQL?

Can someone answer on my dilemma which method to use for connecting Android device to mySQL or Postgresql?

我能做到这两种方式没有任何错误和问题,没有明显的差异,但每个人都建议使用JDBC驱动程序直接连接的网络服务,而不是,

I can do it in both ways without any errors and problems, with no noticeable difference but everyone recommend web service instead of using jdbc driver and direct connection,

的人可以用一​​些事实说明为什么?

Can someone explain why with some facts?

编辑:我did'n提的是更简单,需要更少的做了JDBC的时间。那么,为什么网络服务,或者为什么不?

I did'n mention that is more simple and needs less time to do it over jdbc. So, why web service, or why not?

推荐答案

您的认为的它更简单,更快速地使用JDBC这样做,因为你没有考虑到现实世界中操作的手机和便携式环境设备。他们往往通过马车交通重写代理和疯狂防火墙古怪的连接。他们通常使用具有高和可变数据包丢失率以及延迟该上变化幅度在很短的时间跨度许多订单的网络传输层。 TCP真的不是很大在这种环境下,特别是斗争与长期生活的连接。

You think it's simpler and faster to do it with JDBC because you aren't considering the real world operating environment of phones and portable devices. They often have flakey connectivity through buggy traffic rewriting proxies and insane firewalls. They're typically using a network transport layer that has high and variable packet loss rates and latencies that vary over many orders of magnitude in short spans of time. TCP really isn't great in this environment and particularly struggles with long lived connections.

Web服务的主要优点在于它:

The key benefit of a web service is that it:

  • 目前已与最小国家短期连接,所以很容易找回你在哪里时,该设备切换WiFi网络,向/从蜂窝,短暂失去连接等;以及

  • Has short-lived connections with minimal state, so it's easy to get back to where you were when the device switches WiFi networks, to/from cellular, loses connectivity briefly, etc; and

可以通过所有,但最可怕的和严厉的Web代理

Can pass through all but the most awful and draconian web proxies

您的常规的遇到的问题有直接JDBC连接。一个挑战是可靠超时死连接,重新建立会话,释放由旧会话持有(如服务器可能不能决定它的死亡,同时在客户端所做的)锁。另一种是引起非常缓慢的操作,长期运行的数据库事务,以及随之而来的问题与锁的持续时间和交易清理任务数据包丢失。你也满足了每一个品种的疯狂和破碎的代理服务器和防火墙在阳光下 - 支持连接代理,但后来变成假设所有的流量为https,如果裂伤它不是;防火墙与越野车状态连接跟踪,导致连接失败或去一个半开放式的僵尸状态;每一个NAT问题,你可以想像;运营商有益产生TCP ACK的减少等待时间,没关系,导致数据包丢失发现和调整窗口大小的问题;古怪口堵塞;等等。

You will routinely encounter problems with a direct JDBC connection. One challenge is reliably timing out dead connections, re-establishing sessions and releasing locks held by the old session (as the server may not decide it's dead at the same time the client does). Another is packet loss causing very slow operations, long-running database transactions, and consequent problems with lock durations and transactional cleanup tasks. You'll also meet every variety of insane and broken proxy and firewall under the sun - proxies that support CONNECT but then turn out to assume all traffic is HTTPs and mangle it if it isn't; firewalls with buggy stateful connection tracking that cause connections to fail or go to a half-open zombie state; every NAT problem you can imagine; carriers "helpfully" generating TCP ACKs to reduce latency, never mind the problems that causes with packet loss discovery and window sizing; wacky port blocking; etc.

由于每个人的使用HTTP,你可以期望的工作 - 至少,大大往往比什么都做。尤其是这样,现在常见的网站使用REST + JSON的沟通方式,即使在移动Web应用程序。

Because everyone uses HTTP, you can expect that to work - at least, vastly more often than anything else does. This is particularly true now that common websites use REST+JSON communication style even in mobile web apps.

您也可以写你的Web服务调用是的的使用唯一的请求令牌。这可以让您的应用程序重新发送修改请求,而不必担心它会执行对数据库的操作两次。请参见幂等 definining幂等

You can also write your web service calls to be idempotent using unique request tokens. That lets your app re-send modification requests without fear that it'll perform an action against the database twice. See idempotence and definining idempotence.

严重的是,JDBC从移动设备可能看起来像一个好主意了 - 但我甚至认为这是唯一的办法是,如果移动设备都在我的直接控制一个高可靠的WiFi网络。即使到那时我会避免它,如果我可能可能数据库性能管理的原因。您可以使用类似PgBouncer到池连接多个设备之间在服务器端,以便连接池是不是一个大问题,但丢失和被遗弃的连接清理的,为的是使其工作所需的TCP保持业务和长期停滞从被遗弃的连接的交易。

Seriously, JDBC from a mobile device might look like a good idea now - but the only way I'd even consider it would be if the mobile devices were all on a single high-reliably WiFi network under my direct control. Even then I'd avoid it for reasons of database performance management if I possibly could. You can use something like PgBouncer to pool connections among many devices at the server side so connection pooling isn't a big problem, but cleanup of lost and abandoned connections is, as is the tcp keepalive traffic required to make it work and the long stalled transactions from abandoned connections.

这篇关于JDBC VS Web服务为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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