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

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
LVL 2
krishnamukunthaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
objectsConnect With a Mentor Commented:
> 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
 
objectsCommented:
what driver?
perhaps try a different one
0
 
petmagdyCommented:
I think u need to mention ur Database Vendor and version also information about the jdbc driver u r using
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
krishnamukunthaAuthor Commented:
I am using thin driver.
I can't use other than thin :(-.
0
 
krishnamukunthaAuthor Commented:
JDBC 2.0
JDK 1.3.1.08
Oracle is the DB 8.1.7
0
 
petmagdyCommented:
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
 
CEHJCommented:
>>-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
 
krishnamukunthaAuthor Commented:
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
 
CEHJCommented:
You should just check for (pseudo) Count(Statement.EXECUTE_FAILED) > 1 and *then* rollback, but not otherwise
0
 
CEHJCommented:
Err, i mean

) Count(Statement.EXECUTE_FAILED) > 0

;-)
0
 
krishnamukunthaAuthor Commented:
i think EXECUTE_FAILED is available from jdk1.4
i am using jdk1.3.1
0
 
CEHJCommented:
Actually *both* constants hail from the same version (1.4). You'll have to check for -3
0
 
krishnamukunthaAuthor Commented:
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
 
CEHJCommented:
As long as you know what it means, it doesn't matter ;-)
0
 
krishnamukunthaAuthor Commented:
0
 
CEHJCommented:
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
 
krishnamukunthaAuthor Commented:
rite even it update 0 row i am getting -2
tell me how i can understand there was 0 row got affected?
0
 
CEHJCommented:
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
 
krishnamukunthaAuthor Commented:
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
 
objectsCommented:
yes, I would expect that is the case.
0
 
krishnamukunthaAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.