I am trying to execute a stored proc in java. I know I have to connect to database and do the st开发者_开发百科uff.... But the thing is How do I know that if that stored proc executed successfully? Thanks.
Why not set a OUT parameter returning zero if everything goes fine? I would have p_return_code
and p_return_message
with the other input parameters.
When I make a proc call, I will set them to 0
and Success
within the stored procedure and return them. Do as many data validation after insert/update/delete and finally set to success. I would also handle exceptions and return error messages.
Based on the fact that you are wanting to check that it, "does the right thing to the right data" I'd say this is something you'd need to test while writing the proc...
Your stored proc will do whatever you tell it to, it has no way of determining if that what you "really" wanted it to do. If you are trying to detect an error that's another story.
Can you describe a scenario in which it would execute with no errors but do the "wrong thing to the wrong data"?
never forget to return a number in the procedure, eg. when everything ok return 0, if some other operation failed, return some other number and identify it with the error code you decide to use, eg. 1 - Insert failed
精彩评论