简体   繁体   English

使用Java合并两个ms访问数据库

[英]merge two ms access database using java

I am trying to merge two database of ms access using Java . 我正在尝试使用Java合并两个ms access数据库。 I am making connection from one database and and another connection from other database. 我正在从一个数据库建立连接,而从另一个数据库建立另一个连接。 I am copying all records from each table to the tables in the another database. 我将所有记录从每个表复制到另一个数据库中的表。

Is there any other solution rather than copying records from one database tables to another database tables. 除了将记录从一个数据库表复制到另一数据库表之外,还有其他解决方案吗? both database have the same table structure. 这两个数据库具有相同的表结构。

For the most part, there is a lot more to copying a relational database than simply copying the tables. 在大多数情况下,复制关系数据库要比单纯复制表要多得多。 For example, you must consider the order the data is copied to avoid violating integrity. 例如,您必须考虑复制数据的顺序,以避免破坏完整性。

Regarding the SQL for copying, Access will accept the name of an external mdb / acdb as a detination, so the first two statements will work as long as you have no attachment or multi-value field data types. 关于要复制的SQL,Access将接受外部mdb / acdb的名称作为目标,因此只要您没有附件或多值字段数据类型,前两个语句就可以使用。 Another problem is autonumber IDs, if they are likely to overlap, INSERT INTO is unsafe as you may end up with duplicates. 另一个问题是自动编号ID,如果它们可能重叠,则INSERT INTO是不安全的,因为您可能会重复。

SELECT * INTO AnotherTest IN 'Z:\Docs\test.accdb'
FROM test;

INSERT INTO AnotherTest IN 'Z:\Docs\test.accdb'
SELECT  *
FROM test;

While the above INSERT will often work, it is much safer to list the fields, omitting any autonumber fields. 尽管上面的INSERT通常可以工作,但是列出这些字段(忽略任何自动编号字段)要安全得多。

INSERT INTO AnotherTest ( AText, ADate, ANumber ) IN 'Z:\Docs\test.accdb'
SELECT test.AText, test.ADate, test.ANumber
FROM test;

All the statements were built using MS Access query design window and only slightly modified. 所有语句都是使用MS Access查询设计窗口构建的,仅作了少许修改。

Are you using SQL to do this? 您是否正在使用SQL执行此操作? If so it is probably a question of your SQL code rather then your java code. 如果是这样,那可能是您的SQL代码而不是Java代码的问题。
You could multi-thread your program so that each table or set of tables is copied in a different thread. 您可以对程序进行多线程处理,以便将每个表或一组表复制到不同的线程中。 This is especially useful if the table names don't change as you could create an array of the table names and a thread sub-class that puts the names in your SQL query. 如果表名不变,这将特别有用,因为您可以创建表名数组和线程子类,以将名称放入SQL查询中。 If you used a thread pool of 10 or so threads this should speed it up, although be careful with this as my experience with access and java is that the database can corrupt very easily so make sure you have a backup before trying this. 如果您使用的线程池大约为10个,这应该可以加快速度,尽管请谨慎操作,因为根据我对Access和Java的经验,数据库很容易损坏,因此在尝试执行此操作之前,请确保已备份。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM