How to update bulk no of records using  Batch Update

i am trying to insert and update records into multiple tables using Statement addBatch() and executeBatch() method. But some times it is not executing properly. some tables records are inserting and some tables it is not inserting. But I want all the records need to excute and commit or if any error is there then all records need to rollback.
This is the code i am using.
public String addBatchQueryWithDB(StringBuffer quries, Connection conNew,Statement stmtNew) throws Exception {
String success="0";
try {         
conNew.setAutoCommit(false);
String[] splitquery=quries.toString().trim().replace("||","##").split("\\|");
for(int i=0;i<splitquery.length;i++) {
//System.out.println("query.."+i+".."+splitquery.trim().replace("##","||"));
stmtNew.addBatch(splitquery[i].trim().replace("##","||"));
int[] updCnt = stmtNew.executeBatch();
for(int k=0;k<updCnt.length;k++){
int test=updCnt[k];
if(test>=0){
success=String.valueOf(Integer.parseInt(success)+1);
// System.out.println(".updCnt..."+updCnt[k]);
System.out.println("success...length.."+success);
if(updCnt.length==Integer.parseInt(success)){
success="1";
//conNew.commit();
} catch (BatchUpdateException be) {
//handle batch update exception
int[] counts = be.getUpdateCounts();
for (int i=0; i<counts.length; i++) {
System.out.println("DB::addBatchQuery:Statement["+i+"] :"+counts[i]);
success="0";
conNew.rollback();
throw new Exception(be.getMessage());
} catch (SQLException ee) {
success="0";
System.out.println("DB::addBatchQuery:SQLExc:"+ee);
conNew.rollback();
throw new Exception(ee.getMessage());
} catch (Exception ee) {
success="0";
System.out.println("DB::addBatchQuery:Exc:"+ee);
conNew.rollback();
throw new Exception(ee.getMessage());
}finally {
// determine operation result
if(success!=null && success.equalsIgnoreCase("1")){
System.out.println("commiting......");
conNew.commit();
}else{
System.out.println("rolling back......");
success="0";
conNew.rollback();
conNew.setAutoCommit(true);
return success;
}

Koteshwar wrote:
Thank you for ur reply,
I am using single connection only, but different schemas. Then I am passing a Stringbuffer to a method, and First iam setting con.setAutoCommit(false); and then in that method i am splitting my queries in stringbuffer and adding it to stmt.addBatch(). After that I am executing the batch.after executing the batch i am commiting the connectionIf I am reading that right then you should stop using Batch.
The intent of Batch is that you have one statement and you are going to be using it over and over again with different data.

Similar Messages

  • More than 1 preparedStatement  object using batch update

    Hey how can I execute more than 1 preparedStatement object using batch update..Pls explain with a code(java)
    Thanks

    // turn off autocommit
    con.setAutoCommit(false);
    PreparedStatement stmt = con.prepareStatement(
         "INSERT INTO employees VALUES (?, ?)");
    stmt.setInt(1, 2000);
    stmt.setString(2, "Kelly Kaufmann");
    stmt.addBatch();
    stmt.setInt(1, 3000);
    stmt.setString(2, "Bill Barnes");
    stmt.addBatch();
    // submit the batch for execution
    int[] updateCounts = stmt.executeBatch();
    search in google for more information

  • Want to insert a record using the updatable view object..

    Hi, i am trying to create a new record in my first page using the updatable entity..I set the form in creat mode by default so that it will show empty fields for the first time.It works but want to know the following details..
    1.Want to set default values to some fields ,so how do i override the create method and where(i mean the view object or entity).
    2) internally it is using update query but not insert to insert a new record.
    3) if it uses insert internally, how do i manipulate the insert statement at run time.
    Guys please share ur experience and knowledge with me.I am awaiting for ur help....
    thanks in advance..

    From my perspective, you basically have 2 issues going here, the back end (database) and the front end (web page).
    To simplify your life, test your overridden methods using the built-in tester. You can use it by right-clicking on your application module and selecting test. You can insert/update/delete rows in any updateable view object you have available in your data model. The only down-side is that you can't step through your code (so far as I've been able to determine, anyway).
    As for the web side, there's a commit action in the data control palette. You can drop that onto a page as a button. There's also some tricks you can play so it saves and commits on the same button click, but I don't recall how specifically you do that. I know I've found it searching in here though.

  • How to unlock a row if i use FOR UPDATE clause

    In procedure if we use FOR UPDATE clause, it will lock particular row and allow only one client to update whereas other client can only fetch data in the same row at that time.
    My question is when will it unlock the row, what should we do to unlock the row while writing procedure. Take this example here im using FOR UPDATE clause for client_count, when ll it unlock that particular row in this procedure.
    create or replace PROCEDURE newprocedur(inMerid IN VARCHAR2,outCount OUT NUMBER) AS
    CURSOR c1 IS
    select CLIENT_COUNT from OP_TMER_CONF_PARENT where MER_ID = inMerid FOR UPDATE OF CLIENT_COUNT;
    BEGIN
    Open c1;
    loop
    fetch c1 into outCount;
    exit when c1%NOTFOUND;
    outCount:=outCount+1;
    update OP_TMER_CONF_PARENT set CLIENT_COUNT = outCount where current of c1;
    end loop;
    close c1;
    END;

    Hi,
    Basically you are incrementing client_count by 1 , Why you have to fetch row one by one and update? you could just finish that in a single update
    UPDATE OP_TMER_CONF_PARENT
    SET CLIENT_COUNT = CLIENT_COUNT+1
    WHERE MER_ID     = inMerid This will increment client_count of all rows by one for the given mer_id;
    After updating you have to make the changes permanent so that other users will see the changes you have made.
    To lock the row before update you can use same select statement in you cursor
    SELECT CLIENT_COUNT
    FROM OP_TMER_CONF_PARENT
    WHERE MER_ID = inMerid FOR UPDATE OF CLIENT_COUNT;You can further modify the procedure to let other users know if the row is being updated.
    Regards
    Yoonas

  • How to create relationship between two records using MDM Java APIs

    Hi,
    I am trying to create relationship between two records using Java Apis. Please guide me in doing this.
    Regards,
    Niraj

    Hi Niraj,
    There is ModifyRelationshipsCommand:
    http://help.sap.com/javadocs/MDM/SP06/com/sap/mdm/data/commands/ModifyRelationshipsCommand.html
    Retrieve Relationship command:
    http://help.sap.com/javadocs/MDM/current/com/sap/mdm/schema/commands/GetRelationshipListCommand.html
    Also, please refer similar thread, MDM Java API and relationships.
    Hope it helps..
    Regards,
    Mandeep Saini

  • How to split the crystal report records by batch

    Post Author: dhivya
    CA Forum: General
    Im using a Crystal report and i have to split the records to be printed from the application.For Eg: I Generate a report which has about 2000 pages, now i want to print first 500 as one job and then the second job with the other 500 and til 2000 pages.Now i want to know how to split this records..If i use page count and split for first 500 and then how would the second job know that from where it has to continue (How will it take the 501th record).

    Post Author: Charliy
    CA Forum: General
    When I need to do something like that I use the primary sort field as the limiting feature.  For example: if I'm printing a report sorted by Name I'll have parameters for the first letter of the name.  So if the user enters the range A to E, then only names that start with those letters are printed.  The pages wonlt be exactly as if you'd printed the whole report, but it makes in manageable.

  • I can not update R9 270X hawk vbios using live update

    i can not update R9 270X hawk vbios using live update

    Quote from: Svet on 26-May-14, 21:25:24
    you are using latest legacy vbios
    if you are looking UEFI compatible GOP vbios,
    im attaching latest one for your card
    hi svet. thanks for the reply
    may i know if this is for R9 270X Hawk?
    Im currently using the http://www.msi.com/product/vga/R9_270X_HAWK.html#?div=Specification
    with a
    1100Mhz (Boost: 1150Mhz)    (not the LE edition)
    and how do i flash my GPu.  i dont have experience with other than Live update?

  • How to send BULK email into INBOX using ASP

    Dear Gurus,
    I am using GOMAIL to send newsletter to 2000 of my subscribed
    users. but no
    one is getting their emai intheir inbox
    Only users other than yahoo,hotmail,rediff,gmail are getting
    in their inbox
    I want to know how can I make sure that users who has hotmail
    and yahoo
    accounts also get my newsletter into their inbox cos
    currently it goes to
    their JUNK email or bulk email folder.
    I know lots of companies who send newsletter to my HOTMAIL
    inbox.
    Please suggest as this is very important

    You can send email from javascript in an content editor web part or HTML Form webpart  (if someone is doing this interactively in the browser AND they have an email client installed) by changing the current page ref to a mailto: reference.
    location.href="mailto:"+emailTo+emailSub+emailBody;
    var emailSub = "?subject=xxxxx";
    var emailBody = "&body=xxxxx";
    That will pop up an email window. Build up the emailTo by using Javascript/JQuery to pick up selected people on the page, or all rows on the page, or use something like SPServices or web service calls to pick up all items in a specific view. Depends totally
    on how you want the UI to work. Not sure I'd do this on an external facing SP site since you wouldn't want any emails addresses in the clear to harvest, but inside a company intranet should be fine.
    For example, you could read all records in the Supervisors view, build up the emailTo var with the correct addresses or names that your email client needs, then set location.href to the correct mailto: link.
    Robin

  • How do I change the apple Id used for updating apps and downloading them

    I bought an iPad from someone and I changed the apple ID but for some reason when I try to update the apps the old apple ID comes up from the previous owner ...........I just need to know how I possibly can change it

    You cannot.  Purchases are permanently tied to the AppleID and its account used when making the purchase.  You cannot transfer purchases.
    The reality is you do not own the apps on that iPad - the previous owner does.  If you want them for yourself and want to be able to update them as needed, or re-download them as needed, you will have to delete the copies on the iPad, then purchase them with your own AppleID.

  • How to create IT0128 subtype-02 record using HR_INFOTYPE_OPERATION

    Hi All,
    Can anyone suggest how to use HR_INFOTYPE_OPERATION to create/insert a record in IT0128 for an employee from an ABAP program.
    Some background:::
    Note that the field - "Short Title" which is mandatory in this Infotype. And it uses a Q-structure for its processing. Also it stores this field using a combination of text object, text id, language and text name.
             Text object = HRMESS
             Text id  =  HR_P
    Goto SE16 of an employee and check PA0128, you will notice above fields. The actual value is stored somewhere in system memory using a combination of above 4 fields.
    When i try using my program, it gives me an error "Make an entry in all required fields" (so not able to find how/what should i pass for field "Short Title").  Can anyone suggest how should i use HR_INFOTYPE_OPERATION to create an IT0128 record for subtype 02.
    Appreciate any help asap!!
    Best Regards,
    Abbasi Sadikot
    PS: Please dont post your reply if you dont have any idea of what this is.

    Hi
    HR_INFOTYPE_OPERATION -> calls -> HR_MAINTAIN_MASTERDATA -> this Func. Mod. then creates a batch and calls ->
    -> IF DIALOG_MODE EQ '0'.
    ->    CALL DIALOG 'HR_MAINTAIN_MASTER_DATA' USING BDCDATA MODE 'N'
    ->         EXPORTING
    the SY-SUBRC value after this should be zero. But it isn't. Can anybody suggest something. Or have any idea as what could be going wrong ??
    Here is my program by which i am trying to create IT0128 subtype-02:
    REPORT  ZABTWTEST                                 .
    data: it0128 like p0128 occurs 0 with header line.
    data: return like BAPIRETURN1.
    it0128-pernr = '20123001'.
    it0128-subty = '2'.
    it0128-begda = '20090101'.
    it0128-endda = '20090131'.
    it0128-SPRSL = 'EN'.
    it0128-OBJCT = 'HRMESS'.
    it0128-TXTID = 'HR_P'.
    it0128-OBNAM = '<internally assigned name>'.
    append it0128.
    CALL FUNCTION 'BAPI_EMPLOYEET_ENQUEUE'
      EXPORTING
        number              = '20123001'
        validitybegin       = '19000101'   .
    loop at it0128.
    CALL FUNCTION 'HR_INFOTYPE_OPERATION'
      EXPORTING
        infty                  = '0128'
        number                 = '20123001'
        VALIDITYEND            = it0128-endda
        VALIDITYBEGIN          = it0128-begda
        record                 = it0128
        operation              = 'COP'
        TCLAS                  = 'A'
        NOCOMMIT               = 'X'
      IMPORTING
        RETURN                 = return   .
    endloop.
    CALL FUNCTION 'BAPI_EMPLOYEET_DEQUEUE'
      EXPORTING
        number              = '20123001'
        validitybegin       = '19000101'   .
    write return.   .
    Kindly correct me if i am wrong anywhere.
    Regards,
    Abbasi

  • Pricing not updated in Purchase Info Record using INFREC01. is it possible?

    Hi Gurus,
    I am using IDoc INFREC01 to create Purchase info record for material, but when I see in ME13 that PIR is created successfully but price is never updated, though I have populated field NETPR and EFFPR hence condition PB00 (basic pricing condition) not created.
    Is it possible to update only single pricing (basic price PB00) condition through INFREC01 ??? or should I use another BAPI or some standard report ...??.
    I am extending Pricing Conditions for Purchase inforec through seprate IDOC: COND_A01, but it could only do that if there is basic pricing condition i.e. PB00.
    Please advice.
    Thanks in advance.
    Robin

    HI,
    You can update pricing field for conditon type PB00, please use correct validity period.
    Even there are no basic Price condition PB00, you can add new condition types with existing types.
    Price vaue can depend on the pricing conditions that you have maintained.
    Thanks....

  • How to revert back the loaded records using LSMW tool

    Hi Experts,
    I have question regarding the loading of a flat file using LSMW tool. I loaded the flat file(.txt) data into prodcution server insted of testing server . Is it possible to revert back the data which was loaded into production? Please provide me if any .............
    appriciate your reply
    Thanks
    Kumar.

    Hi,
    This is the link related to your question which has mass deletion of records..Check it out
    http://e-mory.blogspot.com/2008_03_01_archive.html
    Award points if useful.
    Rewards,
    Ravee..

  • How to authorise a computer on iTunes using the updated version?

    I've accidentally deauthorised my computer on iTunes and I'm finding it difficult to find the solution to reauthorise it. Please help!

    Just play a song that requires authorization. There is no need to concern yourself with this until doing so.

  • How do I remove a number sequence using batch rename

    Hi
    I know I've done this in the past but cannot seem to work it out today.
    I have a series of images "_####_[layercompName].png".  I would like to remove the underscores and numbers.  The underscores removal is easy, but how do I remove the numbers (####) when they are different for each filename?  I would like the end result to be [layercompName].png
    The reason I have these filenames in the first place is that I have run the photoshop script "layer comps to files", and this adds a number sequence prefix.  I have tried to alter the script following various instructions I've found from trawling the internet (this one included How do you remove the number sequence when exporting layer comps to files? CS6. Windows 8.) but without any luck.  So now I'm resorting to batch renaming in Bridge.
    Thanks!

    Here you go, taken straight from: DesignEasy: How to Remove Sequence Numbers and Empty Spaces When Exporting Layers and Layer Comps
    Run Adobe Bridge and navigate to the folder with exported files.
    Select all files which have sequence numbers.
    Go to Tools > Batch Rename.
    Choose: String Substitution from the first drop-down list in New Filenamessection. From the second drop-down choose: Original Filename. In the Find: text field type: _\d{4}_ (underscore, backslash, letter d, open bracket, number four, closed bracket, underscore). Leave Replace with: text field blank. Ensure that you have Replace All and Use Regular Expression checked as shown on the screenshot below.
    Click on the Preview button in the top right corner and ensure that files will be renamed as you want.
    Click on Rename button and you are done.
    In case you are first time doing this and you still have doubts if everything will work as expected, check Copy to other folder option when renaming files. This option is located near the top left corner under: Destination Folder.
    Another thing I want to mention is to remove everything that you have below String Substitution options. In case you see additional renaming options just click on minus (-) sign on the right side to remove them.
    How to remove/substitute empty spaces in the file name using Adobe Bridge
    It is pretty similar process. The only difference is that you should type: \s (backslash followed with letter s) in the Find: text field. You can leave Replace with: text field blank or to type underscore.

  • How to get all records using Invoke-webrequest?/Why Invoke-webrequest returns only first 2000 Records?

    invoke-webrequest content returning only 2000 records though it has around 4000 records in web api.
    The same url if I give in excel oData Data feed I am getting all the records.
    See the below script
    Script:
    $QueryResult= (Invoke-WebRequest -Uri $ODataURI -UseDefaultCredentials)
    [xml]$xmlResult=$QueryResult.content
    foreach($obj in $xmlResult.feed.entry.content.properties)
    $Name=$obj.Name;
    $IsAvail=$obj.isAvail.'#text';
    $PGroup=$obj.PGroup
    I am exporting the above result as a CSV file and my CSV file contains only 2000 records. 
    But,  $xmlResult.feed.Count --> it Shows 4000 Records.
    The same Odata url if I give in excel oData Data feed I am getting all the 4000 records.
    So Please help me how can I get all the records using power shell.
    Thanks
    A Pathfinder..
    JoSwa
    If a post answers your question, please click &quot;Mark As Answer&quot; on that post and &quot;Mark as Helpful&quot;
    Best Online Journal

    Hi Jo Swa(K.P.Elayaraja)-MCP,
    Would you please also post code which is used to export the records?
    In addition, to use the cmdlet invoke-RestMethod to work on ODate feeds, please refer to this article:
    Interacting with TechEd NA 2012 Schedule using PowerShell v3
    I hope this helps.

Maybe you are looking for

  • 4s stop charging at 3%

    4s stop charging at 3%. the other timeS it stop at 75% and 92%,  its not the first time alrdy. did i get a faulty set or what? usually battery also depletes vert fast compared to my other friends that is using 4s ,

  • How to make a particular row and column field editable in ALV

    Hi Experts, I have a requirement to make a particular row and column field editable in ALV output. Like i need to make 2nd row - 4th column editable of ALV output. Kindly help me out to solve this. Any help would be appreciated. Thanks, Ashutosh

  • SGD 5.0 and Java 7u45

    A member of our group started using Java 7 update 45 and cannot go to our site running SGD 5.0 with IE. He switch to Firefox which allowed him to contiue after telling us the cert is not valid. However it say it will be blocked in the future java upd

  • Patch Level upgrades

    I am planning an upgrade for a 2007 A customer from PL08 to PL 41. Can I do this in one hit? The help file is a little misleading - is it implying that I have to do an upgrade to PL 30 first? Thanks

  • Copying Results from Production to Despatch

    Dear Experts, We have configured result copying from one inspection lot to another inspection lot. Now our required need to be changed: when we are selecting inspection lot [Source - whcih results need to be copied] system has to propose BATCH instea