Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-27
22
Medium Priority
?
233 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
Comment
Question by:krishnamukuntha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 3
  • +1
22 Comments
 
LVL 92

Expert Comment

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

Expert Comment

by:petmagdy
ID: 12419986
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
ID: 12419988
I am using thin driver.
I can't use other than thin :(-.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

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

Expert Comment

by:petmagdy
ID: 12420065
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
ID: 12420092
>>-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
ID: 12420220
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
ID: 12420322
You should just check for (pseudo) Count(Statement.EXECUTE_FAILED) > 1 and *then* rollback, but not otherwise
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12420324
Err, i mean

) Count(Statement.EXECUTE_FAILED) > 0

;-)
0
 
LVL 2

Author Comment

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

Expert Comment

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

Author Comment

by:krishnamukuntha
ID: 12421656
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
ID: 12421785
As long as you know what it means, it doesn't matter ;-)
0
 
LVL 2

Author Comment

by:krishnamukuntha
ID: 12422857
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12422974
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
ID: 12423106
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
ID: 12423188
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:
objects earned 500 total points
ID: 12428290
> 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
ID: 12430431
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
ID: 12430438
yes, I would expect that is the case.
0
 
LVL 2

Author Comment

by:krishnamukuntha
ID: 12430888
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

609 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