aspose file tools*
The moose likes JDBC and the fly likes Import data from database with sequence as primary key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Import data from database with sequence as primary key" Watch "Import data from database with sequence as primary key" New topic
Author

Import data from database with sequence as primary key

Preeti Prabhakar
Greenhorn

Joined: Jul 27, 2009
Posts: 12
HI all,

I want to import data from another database using JDBC. All the tables have sequence as the primary key and the sequences on the source and destination need not match. I want to enter data into 'N' related tables (having the sequence column as the foreign key) in a single transaction. What is the best approach to achieve this?

Thanks in advance

Preeti Prabhakar
Greenhorn

Joined: Jul 27, 2009
Posts: 12
Well, let me make my question more clear.
I have a Java application (job) which receives data for multiple tables from another schema. These tables have DB sequence as the primary key. Now I want to replicate the data from this schema onto my schema using a Java program. How can i handle sequences and Foreign key references to these sequences while executing the java job?

Thanks in advance.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Welcome to JavaRanch
krish laks
Greenhorn

Joined: May 18, 2007
Posts: 27
Preeti,

in which format your job receives the input data? is it Flat file or delimited file or Excel or some other?

whatever it may be, in the output schema why do you bother about the sequence of the input schema.
Just consider that as input field and persist in your resultant DB schema. If you want you can make that column as PK.

If you have FK columns, first in the referred table then referring table.

Preeti Prabhakar
Greenhorn

Joined: Jul 27, 2009
Posts: 12
Thanks Krish for the response...

I get the input as a flat file.

Say, I have 3 related tables... Student -> Student_Address -> Location. Each of these tables have Sequence as primary key.
I have to import data for all the 3 tables in the same transaction. Is it possible?

Thanks
krish laks
Greenhorn

Joined: May 18, 2007
Posts: 27
Preeti,

I assume Student and Location are independent tables. And Student_Address is dependent on both these tables.
Also from your mail I understand you will get Student_id (PK of student table), Location_id (PK of Location table).
So, you first insert these two tables and then insert the Student_Address table.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Import data from database with sequence as primary key
 
Similar Threads
What is the better choice for primary key ? natural key or system-generated key ?
Comparing two composite keys
Updates work but save throws java.lang.ClassCastException: java.lang.String incompatible
retrieve data frm database
how to Join Multiple tables