Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Save list of objects in one shot

 
lekurwale amol
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to save(insert) a list (arraylist) of objects in one shot in database. Is it possible or I need to use batch statements?
The objects have simple strings as members.
Amol.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by one shot? You will not be able to write a single SQL statement for this, though you will be able to batch a bunch of SQL statements.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on your database, you could do it via a stored procedure. For example, in Oracle you would need to define a database data-type for your "row" objects, plus a table-type (collection) for the list. Then you can have a PL/SQL packaged procedure that receives the list as a parameter, extracts the individual rows from this and takes care of the individual SQL INSERTs. You would need to map your input list from the Java Arraylist to the Oracle "list" type before passing it into the PL/SQL procedure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic