I need to extract additional information from sql exception.
For example I get following exception during query execution http://ora-12899.ora-code.com/ I need to extract column name (without table name). I could do that with regular expressions, but that seems to be very fragile as message may depend on client locale and also it could change when oracle version changes.
How can I get such additional information without message parsing?
I'm sorry, but you can't. The exception is it and in this case you're even lucky that the error contains the column name; generally the error is in the form of "it didn't work" without any kind of context-specific information in it such as a table/column name. I've been told this is because that is security-sensitive information. Which makes sense.
I noticed that plsql developer and sqlplus are able to get position in query string that lead to an error.
For example output from sqlplus:
SQL> insert into tbl (data) values('12345')
insert into tbl (data) values('12345')
ERROR at line 1:
ORA-12899: value too large for column "schmnm"."tbl"."data" (actual: 5,
For my current needs that would be fine. How can I get position in the query string?
This might help (I haven't tried it):
I Googled this:
java getting more information about exception from jdbc driver
and found this:
A Cause: A SQLException instance might..... consists of one or more Trhowable objects... to navigate
this chain of causes, recursively call the method SQLException.getCause.....
You can probably create a simple program that duplicates the exception you get in order to test the above solution.