Solved

ExecuteBatch for update qry giving resultant array having all elements as "-2"

Posted on 2004-10-27
223 Views
Last Modified: 2012-06-27
Hi Dudes
     I am using PreparedStatement and executeBatch() method to update my DB.
In a batach I have 100 update queries approx.
In some situation the where clause does'nt get satisfied and resulting in 0 rows updated.
even in that situation my executeBatch call gives result in int array filled up of  -2(means no info about update).
Is there any othey way to find the update counts in JDBC.( I have to use PreparedStmts only .simple Statement is not allowed as per my guidelines)

your help will be aprreciated with A grade if works fine!!!!!

Krish
0
Question by:krishnamukuntha
    21 Comments
     
    LVL 92

    Expert Comment

    by:objects
    what driver?
    perhaps try a different one
    0
     
    LVL 13

    Expert Comment

    by:petmagdy
    I think u need to mention ur Database Vendor and version also information about the jdbc driver u r using
    0
     
    LVL 2

    Author Comment

    by:krishnamukuntha
    I am using thin driver.
    I can't use other than thin :(-.
    0
     
    LVL 2

    Author Comment

    by:krishnamukuntha
    JDBC 2.0
    JDK 1.3.1.08
    Oracle is the DB 8.1.7
    0
     
    LVL 13

    Expert Comment

    by:petmagdy
    it seems u need to use OraclePreparedStatement in oracle extensions, please read this article:

    http://www.csee.umbc.edu/help/oracle8/java.815/a64685/oraext8.htm


    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    >>-2(means no info about update).

    It means SUCCESS_NO_INFO, so you need to commit the updates so that the updates that *were* a success get applied
    0
     
    LVL 2

    Author Comment

    by:krishnamukuntha
    I used OraclePreparedStatement also in trial it also gives the same.

    I want to rollback if any update query did 0 row update.its not SQLException but my businesslogic says to rollback if ney update query returns<=0

    here i am getting -2 even it sucess!!!!
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    You should just check for (pseudo) Count(Statement.EXECUTE_FAILED) > 1 and *then* rollback, but not otherwise
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    Err, i mean

    ) Count(Statement.EXECUTE_FAILED) > 0

    ;-)
    0
     
    LVL 2

    Author Comment

    by:krishnamukuntha
    i think EXECUTE_FAILED is available from jdk1.4
    i am using jdk1.3.1
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    Actually *both* constants hail from the same version (1.4). You'll have to check for -3
    0
     
    LVL 2

    Author Comment

    by:krishnamukuntha
    rite i am getting -2 but when i do javap there is no contants in my jdk for Statement/PreparedStmt class.
    i dono how that -2 coming for all!!!
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    As long as you know what it means, it doesn't matter ;-)
    0
     
    LVL 2

    Author Comment

    by:krishnamukuntha
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    OK, but that's not a problem. Since you "want to rollback if any update query did 0 row update" all you need to do is catch the exception then rollback
    0
     
    LVL 2

    Author Comment

    by:krishnamukuntha
    rite even it update 0 row i am getting -2
    tell me how i can understand there was 0 row got affected?
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    You've just pointed me to the API doc on that class:

    "Returns:
    an array containing one entry per each element in the batch. Each value is always -2."

    i.e. (don't ask me why) the value is always -2. The fact that you're not seeing an update after getting no exception could be due to various factors, such as the fact that the connection on which you're doing the select afterwards cannot read uncommitted data and you've not committed the updates
    0
     
    LVL 92

    Accepted Solution

    by:
    > tell me how i can understand there was 0 row got affected?

    you can't with the driver you are using, as it is not supported by your driver.
    You will need to use a different driver as I originally suggested.

    The other option would be to not do a batch update, or use a stored proc to handle the update if appropriate.
    0
     
    LVL 2

    Author Comment

    by:krishnamukuntha
    Pls clarify me ...
    If we use Oracle Driver then even we fire JDBC 's PreparedStmt it will actually use the OraclePreparedStatement class only rite?
    0
     
    LVL 92

    Expert Comment

    by:objects
    yes, I would expect that is the case.
    0
     
    LVL 2

    Author Comment

    by:krishnamukuntha
    K then i don't have any option to do thru APIs so let us stop this thread.
    Thanks a lot for all you replies
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now