BATCH Program in JDBC....VERY URGENT

Discussions

Performance and scalability: BATCH Program in JDBC....VERY URGENT

  1. BATCH Program in JDBC....VERY URGENT (3 messages)

    Hi pals,
             In my current project I have a suitation where i need to run batch program in java.
             I know that java is not ment to fullfill the need of batch programing but management
             persisting in writting it in java.
             
             ##### Scenario for Batch ###
             
             I need to parse XML file with using JDOM parser.
             I am putting this parsing info in ArrayList.
             and passing this Arraylist to insert into the Database.
             
             ########## Now Problem ############
             
             When i am inserting it into Data Base my requirment is to put the Data in Batch to DB.
             
             So i am using executeBatch() method of JDBC 2.0.
             
             Now according to the requirement if during the execution of the executeBatch()
             if database problem occurs the records excuted earlier need to be commited and records
             follows the faulty records need not to inserted.
             
             For Example
             
              Suppose I have 10 records
              
              if exception raise like batch Exception at 6 th record the all the
              5 records of the before 6th need to be commited and remaining of the
              record after 6th need not to be inserted in database.
              
              
              I am very clewless for this suitation...
              Pls some one do the need full by reply me very URGENTLY..
              With Some Good Suggestion

    Threaded Messages (3)

  2. I don't think the solution below is good, anyway it's still perform according to your requirement but with some issues. U can have a try....

    Solution
    ...........
    1) U can add commit statement after every query in the batch. This look really silly.... (performace penalty on every commit statement). So for the senario below, the query1 will commited if coz query2_error .....

    ...
    con.setAutoCommit(false);
    Statement stmt = con.createStatement();
    stmt.addBatch(updateQuery1);
    stmt.addBatch("commit");
    stmt.addBatch(updateQuery2_Error);
    stmt.addBatch("commit");
    stmt.addBatch(updateQuery3);
    stmt.executeBatch();
    con.commit();
    ...

    2)u can try to call con.commit() if any exception occur during batch
    update.

    ...
    try{
      con.setAutoCommit(false);
      Statement stmt = con.createStatement();
      stmt.addBatch(updateQuery1);
      stmt.addBatch("commit");
      stmt.addBatch(updateQuery2_Error);
      stmt.addBatch("commit");
      stmt.addBatch(updateQuery3);
      stmt.executeBatch();
      con.commit();
    }catch (Exception e){
      try {
        con.commit();
        .....
       }catch (Exception e1){
         System.out.println("unable to commit Exception="+e1);
       }
    }
    ...
  3. minor mistake[ Go to top ]

    The solution 2 should remove all the added commit.....
    > 2)u can try to call con.commit() if any exception occur during batch
    > update.
    problem if exception due to network issue not coz of updateQuery error.
    >
    > ...
    > try{
    >   con.setAutoCommit(false);
    >   Statement stmt = con.createStatement();
    >   stmt.addBatch(updateQuery1);
    >   stmt.addBatch(updateQuery2_Error);
    >   stmt.addBatch(updateQuery3);
    >   stmt.executeBatch();
    >   con.commit();
    > }catch (Exception e){
    >   try {
    >     con.commit();
    >     .....
    >    }catch (Exception e1){
    >      System.out.println("unable to commit Exception="+e1);
    >    }
    > }
    > ...
  4. BATCH Program in JDBC....VERY URGENT[ Go to top ]

    If it is so god-damned URGENT, figure it out on your own and don't waste your time at this forum.

    Hurry!