db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Pendleton <bpendleton.de...@gmail.com>
Subject Re: Transfer data between tables that are located in different databases
Date Sun, 25 Apr 2010 14:37:59 GMT
> Could someone give me pointers on how to transfer data between two 
> tables that are identical in structure, but located in different 
> databases. This task needs to be accomplished through code.

A single program can certainly have multiple databases open. Each
java.sql.Connection object is tied to a single database, but you can
have several Connection objects, each pointing to a different database,
and switch back and forth between them in your program as you need to.

If it's a lot of data, you could run the export/import system procedures.
Export the data from the source table to a text file, then import it
to the target table.

If it's a small amount of data, you can open two connections in your
program, read the data from the source table, and insert the data
into the target table.

Depending on how generic your transfer code needs to be, you could
simply hard-code the names of columns and their data types in your code.
Or, you could use the DatabaseMetaData classes to determine the
column names at runtime and write a generic transfer routine.

Why don't you post the code you've tried so far, and the problems
you've encountered, and the community can then suggest solutions
to those problems.



View raw message