Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send database data through socket connection

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).

Thank you very much!!

like image 986
javment Avatar asked Apr 19 '26 21:04

javment


1 Answers

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>

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.

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.

Example:

{name: John, age: 30 }
like image 69
Gressie Avatar answered Apr 21 '26 11:04

Gressie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!