Results 1 to 2 of 2

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

  1. #1
    Join Date
    Jun 2007
    Posts
    2

    Default 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. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    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 at 11:53 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •