Forums Register Login

How to throw an Exception from SQL code

+Pie Number of slices to send: Send
I need a table called "asset" which contains assets, would you believe. Now it is possible to buy an asset, so I wrote a stored procedure, and I can easily write a stored procedure for disposing of an asset (eg sold, damaged, stolen). MySQL 5.0.51 or thereabouts.

But I don't want to call the dispose_of_asset procedure twice on the same asset. Is there any way to write SQL code which will raise an SQLException on JDBC if the dispose_of_asset procedure is called on something which has already been disposed of?

I have found this by Googling, which said to select a non-existent column. Is there a more elegant way to do it.
+Pie Number of slices to send: Send
Do you have to have the stored procedure throw an exception, or could you have it return one value if it did its work correctly and a different value if it failed?
+Pie Number of slices to send: Send
It isn't actually returning a value at present, so I could return TRUE or FALSE and use ROLLBACK; if the asset has already been disposed of.
+Pie Number of slices to send: Send
Thank you. I shall try changing it to a function with a boolean return type. Then whoever implements the JDBC bit (myself) will know to watch for that return.
no wonder he is so sad, he hasn't seen this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1924 times.
Similar Threads
getting ResultSet from Java Stored Procedure
Stored Procedure problem
SQL server 7.0 and Java
writing log to a file from java stored procedure
Pass ArrayList To Oracle
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:30:49.