Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Batch Insert

 
Arulanand Dayalan
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am using oracle database. I want to do a batch insert, i want to know is it possible. I have Distribution Class which contains Distribution Package Id, Product Type List and Channel List. I have around List of 50000 Distribution objects which needs to be inserted into DB.

I have two table Product , Product Channel.

Product - Product Id (Sequence,PK),Package Id, Product Type
Product Channel - Proudct Id , Channel Type

I want to do the insert as batch so that i can improve performance. My algorithum would look like thsi,

for each Distribution Object in the List
Get the Package Id
Get the Product List
Get the Channel List
for each Product Type in the Proudct List
insert in to DB - Product Type,Package Id. Get the Product Id
for each Channle in the Channel List
insert in to DB - Product Id,Channel Type
end
end
end

It would be great if some could tell how to do it or guide me to some resources where i could get more information.

Thanks in Advance.

Regards,
Arul.
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic format for creating and executing a batch in JDBC 2 is:


However, given the complexity of your specific code, you may want to look at creating a stored procedure and calling it, as that will make it easier to leverage getting the ID back from the first insert, etc.

You could also look into a batch insert using a select subquery ("insert into TABLE () values select ...")
 
Arulanand Dayalan
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stevi Deter for quick reply. I am planning to do this using Stored Procedure. Think this way it would perform better.

Regards,
Arul.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic