aspose file tools*
The moose likes JDBC and the fly likes executeBatch of Statement --- jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "executeBatch of Statement --- jdbc" Watch "executeBatch of Statement --- jdbc" New topic
Author

executeBatch of Statement --- jdbc

vianyrajnish rajnish
Ranch Hand

Joined: Apr 22, 2007
Posts: 70
hi all,

I am writing one jdbc program ( using mysql) in which i am executing the 4 statements , using executeBatch() method of Statement .

2 insert queries --- insert two new records
1 update query ----- update a field in a row
1 delete query ----- delete a row based on some field.

here in delete query i am using the field value which doesn't exists
ex : delete from student where sid=888 ; ( and student with 8888 doesn't exists)

0utput when i print constants of statement:--
x[0]=1 (because 1 row inserted )
x[1]=1 (because 1 row inserted )
x[2]=2 (because 2 rows updated )
x[3]=0 (because there are no row with sid = 888)
value of SUCCESS_NO_INFO = -2
value of EXECUTE_FAILED = -3

my question is what these values means SUCCESS_NO_INFO = -2, EXECUTE_FAILED = -3 ? and also delete has not happen because no row with sid=888 still why the executeBatch is executed successfully here.?

thanks,
vinay rajnish
Tarun Yadav
Ranch Hand

Joined: Sep 20, 2007
Posts: 134
Delete and update queries don't throw an error when the rows to be deleted don't exist; try it out on the DB yourself. You'll simply get messages saying '0 rows deleted' or '0 rows updated'.

And the values you're talking about are constants in the Statement interface, quote from the docs:

SUCCESS_NO_INFO The constant indicating that a batch statement executed successfully but that no count of the number of rows it affected is available.

EXECUTE_FAILED The constant indicating that an error occured while executing a batch statement.


The JavaDocs Statement http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#SUCCESS_NO_INFO
vianyrajnish rajnish
Ranch Hand

Joined: Apr 22, 2007
Posts: 70
hi ,

But what these values represents ... (-2 and -3) when the above executeBatch is done. what these values means....

value of SUCCESS_NO_INFO = -2
value of EXECUTE_FAILED = -3

Thanks,
Vinay Rajnish
vianyrajnish rajnish
Ranch Hand

Joined: Apr 22, 2007
Posts: 70
hi ,
when and how these constants are used ?
- SUCCESS_NO_INFO

Thanks,
Vinay rajnish
Tarun Yadav
Ranch Hand

Joined: Sep 20, 2007
Posts: 134
Originally posted by vianyrajnish rajnish:
hi ,
when and how these constants are used ?
- SUCCESS_NO_INFO

Thanks,
Vinay rajnish


Again, I'd point you towards the docs, look at the entry for executeBatch(), it explains when these values are returned.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: executeBatch of Statement --- jdbc