• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Forcing a BatchUpdateException

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am in the process of writing unit tests and I want to force a BatchUpdateException to make sure my code deals with this scenario. I use the statement.executeBatch() method to delete multiple rows from a table which is working fine.

What is the best way to go about this. What would cause an exception of this type to be thrown? A sql syntax error or just some underlying undeterminable error?

I am using MySql.

Thanks.
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what about if you simply throw a new BatchUpdateException()

Shailesh
 
craig a chapman
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I did think of that but I'm not sure its that straight-forward. I have a struts based web app and I am performing in-container unit testing. The particular struts action calls a delete method of my DAO, catches any exceptions, determines if it's a BatchUpdateException (BUE), and from the updateCounts I can determine which rows were not deleted, as the array of update counts is in the same order as the statements were executed, and therefore provide a useful error message.

To do as you suggest, I think I'd need to create a separate DAO that deliberately throws a BUE for test purposes only but that isn't testing my product code.

This test just involves setting some request parameters and invoking the actionPerform method of the struts action. I have control over the parameters for the sql statement, so it would be useful if I could do something with them to cause a BatchUpdateException.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic