通过套接字连接发送数据库数据 [英] Send database data through socket connection

查看:258
本文介绍了通过套接字连接发送数据库数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分布式的java应用程序,我想在分开的计算机系统或android设备的两个数据库之间发送数据库数据。哪个是传递表数据抛出套接字连接的最好方法?我想将发送表行作为文本行,或者xml元素或创建一个类(实现Serializable接口)为每个表,并传输该对象的数组列表每个表。在你看来更有效的解决方案是什么?有什么其他方法吗?数据库可能不同,像mysql,sqlite,h2database所以我不能使用任何数据库本机函数syncronize(这里虽然我serach为一些类似我读一些关于orable数据库,有这样的功能)。

I have a distributed java application and I want to send the database data between two databases which are in seperate computer systems or android devices. Which is the best way to transfer tha table data throw a socket connection?I think about send table rows as a text lines, or xml elements or create a class(implements the Serializable inteface) for every table and tranfer an arraylist of that objects for each table. Which is in your opinion the more effetive solution? There is any other way to do that? the databases may are different like mysql, sqlite, h2database so I can't use any database native function to syncronize(here while I serach for somthing similar I read something about orable database, have a function like this).

非常感谢!

推荐答案

我个人认为XML太繁琐, ,您最终可能会获得一半的内容数据量,一半的结构数据。

Personally I consider XML too verbose for transferring data, you might end up with half the amount of data for content and half for structure.

<record>
   <name>John</name>
   <age>30</age>
</record>

大部分空间在定义结构时会丢失, ,30)。

Most of the space is lost in defining the structure, little is left for the data you want (John, 30).

纯文本行太有限,至少必须考虑逗号分隔值。

Plain text lines are too limited, at least consider comma seperated values if you must.

Name;Age
John;30

第一行只是标签,如果你确定不会改变你可以删除它。

The first row is just for labels, if you're pretty sure that will never change you can remove it.

对象的序列化可能太危险传输数据,因为你可能会产生不兼容性使得反序列化失败。例如,引入或删除字段就足够了。

Serialization of objects can be too dangerous to transfer data, since you might create incompatibilities over time that make deserialization fail. For example, introducing or removing a field is enough.

看看 JSON ,它不像XML那么冗长,结构不仅仅是行。很重要的一点是,您可以在两端正确处理数据,但是您知道发送的结构可以正确转换。

Have a look at JSON, it's not as verbose as XML and more structured than just lines. The important part is of course that you handle your data properly at both ends, but given you know the structure sent you can transform it properly.

示例:

{name: John, age: 30 }

这篇关于通过套接字连接发送数据库数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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