将不同来源的数据合并到数据库
我必须比较两个不同来源的数据。
从不同的来源,我需要获取 College_id、student_id、student_name &我想检查它们在我的数据库中是否是最新的。来源始终拥有准确的数据。
一所大学可能有多个记录。
每次登录时,我都需要在数据库中更新此信息。我该如何继续?
删除&我们的团队不推荐插入选项。那么,我该如何比较呢?
谁能提供一些有效的伪代码?我应该将源信息存储在Java中的二维数组中还是列表中或者如何存储?
如果该记录不存在于源中但存在于数据库中,那么我需要将其从数据库中删除。
如果记录存在于源&数据库中不存在,我需要将其插入到数据库中。
如果有人可以通过一些伪代码提供关于是否使用列表或二维数组的见解,我将不胜感激。
谢谢!
I've to compare data from 2 different sources.
From a different source, I need to get college_id, student_id, student_name & I want to check if they are up-to-date in my database. The source is always having accurate data.
One college may have multiple records.
Every time I login I need to keep this information up-to-date in my database. How do I proceed?
Delete & insert option is not recommended by our team. So, how do I compare?
Can any one provide some efficient pseudo code? Should I store source information in 2-D array in Java or in list or how?
If the record does not exist in source but exist in database, then I need to delete it from DB.
If the record exists in source & does not exist in db, I need to insert it in db.
Appreciate if some one can provide an insight whether to use list or 2-D array with some pseudo code.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,您需要
问题是,您没有为记录指定主键,因此#5 可能不相关。
对于所有其他人,您需要一个封装记录的类,实现 equals() 和 hashCode() 方法(正确!),以及几个集合,其中包含了解
removeAll()
和retainAll()
方法。希望有帮助。
附言。确实可以增量地执行此操作,例如,如果您没有足够的内存来填充整个数据集。在这种情况下,您需要能够读取有序的记录,并且排序与等价关系兼容。
Basically, you need to
Problem is, you do not specify the primary key for your records—so #5 may be irrelevant.
For all others, you need a class which encapsulates a record, implements an
equals()
andhashCode()
methods (properly!), and a couple of collections, with a knowledge ofremoveAll()
andretainAll()
methods.Hope that helps.
PS. It is indeed possible to do this incrementally, e.g. if you haven't got enough emory to fill the whole dataset. In this case, you will need an ability to read the records ordered, with ordering compatible with equivalence relation.
您概述了问题中的大部分步骤。只要进行同步即可:
You outlined most of the steps in your question. Just go through and, whenever you are syncing: