oracle JAVA如何同步远程数据库和本地数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1414250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:59:19  来源:igfitidea点击:

How to synchronize remote database with local database in JAVA

javaoraclejpasynchronization

提问by Xinus

I need to create project in which there are two databases local and remote. Remote database needs to be synchronized daily with local database reflecting changes made in local database. I am using JAVA. Database is ORACLE. I have JAVA/JPA code that does CRUD operations on local database. How to synchronize changes to remote database.

我需要创建一个项目,其中有两个本地和远程数据库。远程数据库需要每天与本地数据库同步,反映本地数据库中所做的更改。我正在使用 JAVA。数据库是ORACLE。我有在本地数据库上执行 CRUD 操作的 JAVA/JPA 代码。如何将更改同步到远程数据库。

回答by Stu Thompson

I would not do this in Java, but look for native Oracle database synchronization mechanisms/tools. This will

我不会在 Java 中这样做,而是寻找本机 Oracle 数据库同步机制/工具。这会

  • be quicker to implement
  • be more robust
  • have faster replicationevents
  • be more 'correct'
  • 更快地实现
  • 更稳健
  • 更快的复制事件
  • “正确”

回答by Miserable Variable

Please look at some synchronization products. SQL Anywhere from Sybase where I work is one such product. You may be able to get a developer/evaluation copy that you can use to explore your options. I am sure Oracle has something similar too.

请看一些同步产品。我工作的 Sybase 的 SQL Anywhere 就是这样一种产品。您可以获得一份开发人员/评估副本,您可以用它来探索您的选择。我相信 Oracle 也有类似的东西。

The basic idea is to be able to track the changes that have happened in the central database. This is typically done by keeping a timestamp for each row. During the synchronization, the remote database provides the last sync time and the server sends to it all rows that have changed since then. Note that the rows that have been deleted in the central database will need some special handling to ensure they get deleted from the remote database.

基本思想是能够跟踪中央数据库中发生的更改。这通常通过为每一行保留时间戳来完成。在同步期间,远程数据库提供上次同步时间,服务器将自那时起更改的所有行发送给它。请注意,已在中央数据库中删除的行需要进行一些特殊处理以确保它们从远程数据库中删除。

A true two-way synchronization is lot more complex. You need to also upload the changes from remote database to central and also some conflict resolution strategies have to be implemented for the cases when the same row has been changed in both the remote and central database in incompatible way in the two.

真正的双向同步要复杂得多。您还需要将更改从远程数据库上传到中央数据库,并且对于在远程和中央数据库中以不兼容的方式更改同一行的情况,还必须实施一些冲突解决策略。

The general problem is too complex to be explained in a respone here but I hope I have been able to provide some useful pointers.

一般问题太复杂,无法在此处的回复中解释,但我希望我能够提供一些有用的指示。

回答by Bill K

The problem is that what you are asking can range from moderately difficult (for a simple, not very robust system) to a very complex product that could keep a small team busy for a year depending on requirements.

问题在于,您所要求的范围可以从中等难度(对于一个简单的、不是很健壮的系统)到一个非常复杂的产品,根据需求可以让一个小团队忙碌一年。

That's why the other answers said "Find another way" (basically)

这就是为什么其他答案说“寻找另一种方式”(基本上)

If you have to do this for a class assignment or something, it's possible but it probably won't be quick, robust or easy.

如果您必须为课堂作业或其他事情这样做,这是可能的,但它可能不会快速、可靠或容易。

You need server software on each side, a way to translate unknown tables to data that can be transferred over the wire (along with enough meta-data to re-create it on the other side) and you'll probably want to track database changes (perhaps with a flag or timestamp) so that you don't have to send each record over every time.

您在每一端都需要服务器软件,一种将未知表转换为可以通过网络传输的数据的方法(以及足够的元数据以在另一端重新创建它),并且您可能想要跟踪数据库更改(也许带有标志或时间戳),这样您就不必每次都发送每条记录。

It's a hard enough problem that we can't really help much. If I HAD to do that for a customer, I'd quote him at least a man year of work to get it even moderately reliable.

这是一个足够困难的问题,我们真的帮不上什么忙。如果我必须为客户做这件事,我会引用他至少一年的工作,以使其更加可靠。

Good Luck

祝你好运

回答by APC

Oracle has a sophistication replication functionality to synchronise databases. Find out more..

Oracle 具有复杂的复制功能来同步数据库。 了解更多。.

From your comments it appears you're using the Oracle Lite: this supports replication, which is covered in the Lite documentation.

从您的评论看来,您正在使用 Oracle Lite:它支持复制,这在Lite 文档中有所介绍。

回答by vlddrak

Never worked with it, but http://symmetricds.codehaus.org/might be of use

从未使用过它,但http://symmetricds.codehaus.org/可能有用