views:

305

answers:

1

Hi,

The problem that I am facing is primarily on Exception Handling! When an exception occurs I want to put that data in another log table with the error message. However, in DB2 I am not able to figure out a way to retrieve the corresponding error message for the raised SQLSTATE.

PS: I have a stored procedure for this migration and I am not using any other language to call it.

Though, I have already queried about this and infact I got some valuable pointers.

Refer: http://stackoverflow.com/questions/1096340/db2-exception-handling

However, if I use the basic SQLERRM function then for a basic 23502 I get the following message:

"SQLSTATE 23502: An insert or update value is null, but the column cannot contain null values."

Whereas what I really want is the Column name that threw this error, appended to this message! Is there any way, the DB2 could give me a complete error, with the column name the error was raised in?

Thanks in advance ;-)...

Harveer

A: 

You need to retrieve all of the tokens from the SQLCA when you encounter such an error. The tokens will contain either the table name and column name, or the numeric table id and column position within the table, starting with zero. The SQLERRM function takes in those tokens and uses them to reconstruct an error message that is as detailed as what you see from the command line.

Fred Sobotka