tags:

views:

301

answers:

1

I am creating a sybase stored prodedure that is being called through JDBC. Under certain error conditions i want my stored procedure to return a warning to the JDBC caller. What do i need to add to the stored procedure so

Statement.getWarnings()

returns a SqlWarning that contains an error message of my choice?

+1  A: 

Unless I'm mistaken, you can remap SQL exceptions to SQL warnings, using error message handlers. More information can be found in the jConnect 6 Programmer's Reference. Information is available on how to create a custom message handler is available in Chapter 2, in the section on handling error messages.

This, of course means that you will still have to raise errors via raiserror in the stored procedure with the only benefit that you can remap certain errors to warnings. The complexity of the message handler will be proportional to the number of user errors raised by your stored procedure.

The reason why SQLExceptions will be raised, instead of SQLWarnings when you raise an error from the stored procedure is because Sybase automatically sets the severity of user errors to 16 - termed as "Miscellaneous User Error". Errors of severity level 16 are automatically converted to SQLExceptions.

Vineet Reynolds