Sending database data through a socket connection

I have a distributed Java application and I want to send database databetween two databases that reside on separate computer systems or Android devices. What is the best way to transfer table data to cause a socket connection? I am thinking of sending table rows as text strings or xml elements or creating a class (implements a Serializable inteface) for each table and translating the arraylist of these objects for each table. What, in your opinion, is a more effective solution? Is there any other way to do this? databases can be different, for example, mysql, sqlite, h2database, so I can not use any basic database function for synchronization (here, while I serach for somthing similar, I read something about orable database , I have such a function).

Many thanks!

+2
source share
2 answers

Personally, I think that XML is too verbose to transmit data, you can get half the amount of data for the content and half for the structure.

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

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

Simple text strings are too limited, at least consider commas separately if you should.

Name;Age
John;30

The first line is for labels only, if you are sure that you will never change it, you can delete it.

Serializing objects can be too dangerous for data transfer, as you can create incompatibilities over time that result in deserialization. For example, just enter or delete a field.

JSON, , XML , . , , , , , , , .

:

{name: John, age: 30 }
+1

, , .

. JPA .

, . , , , . , , , .

, . JPA Gson ( HornetQ). .

, , . , ( Gson) JMS, ( ) .

. , - .

...!:)

+1

Source: https://habr.com/ru/post/1625456/


All Articles