This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forcing a BatchUpdateException

 
craig a chapman
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic