File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executeBatch of Statement --- jdbc

 
vianyrajnish rajnish
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
when and how these constants are used ?
- SUCCESS_NO_INFO

Thanks,
Vinay rajnish
 
Tarun Yadav
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic