-1

I am inserting 132,000 records in a database table using jdbc batch of prepated statement. The problem i am facing is all records are not inserted in to table only records 1444 are inserted.

try{
        StringBuffer insert = new StringBuffer("INSERT INTO mytable (field1,field2,
,field3,field 4 )   VALUES ( ?, ?, ?, ? )");

          pstmt = conn.prepareStatement(insert.toString());
          Iterator cptIcd9Iterator = cptIcd9List.iterator();    
          while(cptIcd9Iterator.hasNext()){
              cptIcd9VO = (CptIcd9VO)cptIcd9Iterator.next();            
              count++;
              pstmt.setString(1, "field1");
              pstmt.setString(2, "field2");
              pstmt.setString(3, "field3");
              pstmt.setInt(4, 4);
              pstmt.addBatch();
          }
           updateCounts = pstmt.executeBatch();
    }
    catch (Exception e) {
        logger.error(e);
   }

Can anyone help me ?

Zeeshan
  • 1,095
  • 3
  • 19
  • 25

1 Answers1

2

You can't insert all of them in one go, you must do it step by step.

Read this SO post.

Community
  • 1
  • 1
darioo
  • 43,550
  • 10
  • 71
  • 102