• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

executeBatch of Statement --- jdbc

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic