Announcement Announcement Module
Collapse
No announcement yet.
How to do the batch insert from one table into other? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to do the batch insert from one table into other?

    One way is to:
    1. retrieve all records from I/P table in a List object
    2. Create sql string
    3. Create BatchPreparedStatementSetter
    - where public int getBatchSize(){
    return objList.size();
    }
    - And public void setValues(PreparedStatement ps, int index) throws SQLException{
    Record rec = (Record)objList.get(index);
    ps.setString(1,rec.getFirst());
    ps.setString(2,rec.getFirst());
    }

    4. jdbcTemplate.batchUpdate(sql,setter);

    But the concern is I/P table may have >50K records so don't want to get in a List. I have little knowledge about is it good to retrieve such a huge data in a List. Is there any other way where I can retrieve each record and pass it to the BatchPreparedStatementSetter without getting the List involved? And if data retrieving into List is the only way to get it done, then kindly let me know how can I control the block wise insertion. Highly appreciated if I can get some code snippet.

    I m using JDBCTemplate within DBBaseObject for data access operation.

    Thanks.
    Prem

  • #2
    If this is just a one off task you might want to use the database tools to do this. Do you need to go into code, couldn't you execute this in one statement? If not then you want to have a look at paginating the data, there are lots of discussions on the net about this.
    http://www.sqlteam.com/article/using...insert-records
    Last edited by karldmoore; Aug 29th, 2007, 11:53 AM.

    Comment

    Working...
    X